liveBook · Manning

Scheduler

As explained in Spring in Action, Sixth Edition

A Project Reactor scheduler provides an execution context and worker resources for running reactive tasks.

A Project Reactor scheduler supplies the execution context and worker resources used to run reactive tasks. Use subscribeOn() to choose how subscriptions execute concurrently. section 11.3.3

Parallel transformations

Combine flatMap() with subscribeOn(Schedulers.parallel()) to transform several values asynchronously. The fixed worker pool is sized to CPU cores, so throughput can increase, but emitted items may arrive in an unpredictable order. section 11.3.3

Table 11.1 Concurrency models for Schedulers (view table figure)

Schedulers method

Description

.immediate()

Executes the subscription in the current thread.

.single()

Executes the subscription in a single, reusable thread. Reuses the same thread for all callers.

.newSingle()

Executes the subscription in a per-call dedicated thread.

.elastic()

Executes the subscription in a worker pulled from an unbounded, elastic pool. New worker threads are created as needed, and idle workers are disposed of (by default, after 60 seconds).

.parallel()

Executes the subscription in a worker pulled from a fixed-size pool, sized to the number of CPU cores.

Compare immediate, single-threaded, dedicated-thread, elastic-pool, and CPU-sized parallel execution models. section 11.3.3

How Spring in Action, Sixth Edition covers it

How deep it goes
Defines five scheduler modes and demonstrates parallel execution, but stops short of scheduler internals.
Examples
Demonstrates player-name mapping, buffered fruit processing, parallel workers, and interleaved execution logs.
What it assumes
Assumes basic Flux, Mono, subscription, and stream-operator knowledge while distinguishing subscribe() from subscribeOn().
What you can do after
Apply it via Schedulers and subscribeOn() to distribute reactive work across selected worker models.
How it connects
Connects reactive streams with Flux, Mono, flatMap(), subscribeOn(), and asynchronous transformations.

Also explained in

Compare how 12 books explain scheduler →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Spring in Action, Sixth Edition. The section links point to the parts of the book it draws on.