The Schedulers class in Project Reactor is a factory for Scheduler instances, which decide on which thread (or thread pool) parts of a reactive pipeline run. Reactor itself is concurrency-agnostic: a pipeline runs on the thread that subscribes to it unless you move work with subscribeOn, publishOn, or an operator that takes a Scheduler, such as delayElements or interval.
Choosing the right scheduler keeps CPU-bound work off I/O threads, isolates blocking calls, and makes tests deterministic.
A Scheduler is an abstraction over an executor: it can run a task now, run it after a delay, or run it periodically, and it hands out Worker objects that execute tasks sequentially on one thread. Schedulers gives you ready-made implementations so you rarely create executors yourself.
By default nothing is asynchronous. In the example below everything runs on main:
The static factory methods on Schedulers return shared, lazily created instances:
| Factory method | Backing threads | Use it for |
|---|---|---|
Schedulers.immediate() | The caller thread | Running work inline, mostly in tests or APIs that require a Scheduler |
Schedulers.single() | One reusable thread | Low-latency tasks that must not run concurrently |
Schedulers.parallel() | Fixed pool, one worker per CPU core by default | Short, non-blocking, CPU-bound work |
Schedulers.boundedElastic() | Growing pool with an upper bound, idle threads are reclaimed | Blocking calls such as JDBC, file I/O, or legacy SDKs |
Schedulers.fromExecutorService(es) | Your own ExecutorService | Integrating an existing pool |
The older Schedulers.elastic() is deprecated because its pool was unbounded; use boundedElastic() instead. The bounded pool caps both the number of threads and the number of queued tasks, so a flood of blocking work degrades gracefully instead of exhausting memory. Recent Reactor versions can also back boundedElastic() with virtual threads through the reactor.schedulers.defaultBoundedElasticOnVirtualThreads system property; check the reference documentation for the version you use.
Never run blocking code on parallel() or single(). They are sized for non-blocking work, and a blocked thread there stalls every other pipeline sharing it.
The two operators move work differently, and mixing them up is the most common mistake.
subscribeOn changes the thread used for the subscription and therefore for the source and everything upstream that has no publishOn after it. Its position in the chain does not matter.
publishOn changes the thread for everything downstream of where you put it. Its position matters.
The source and the map run on a boundedElastic thread because of subscribeOn; after publishOn the rest runs on parallel. The Thread.sleep is only there because these schedulers use daemon threads and main would otherwise exit first.
A frequent need is calling a blocking API from a reactive chain. Wrap it in Mono.fromCallable and subscribe it on boundedElastic:
The blocking call now occupies a thread from the bounded pool, and the event-loop or parallel threads stay free. Tools such as BlockHound can detect accidental blocking calls on non-blocking threads during tests.
When you need isolation, for example a dedicated pool for one slow dependency, create a named scheduler and dispose of it when it is no longer needed:
newParallel and newSingle follow the same pattern. The shared instances returned by parallel(), single() and boundedElastic() should not be disposed manually in application code.
Operators such as Flux.interval, delayElements, and timeout use Schedulers.parallel() by default and accept an explicit Scheduler. For tests, StepVerifier.withVirtualTime replaces the default schedulers with a virtual-time scheduler, so a test with a ten-minute delay finishes immediately:
Create the delayed publisher inside the supplier lambda, otherwise it is built before the virtual clock is installed.
There is none for plain operators: the pipeline runs on the subscribing thread. Only time-based operators such as interval and delayElements default to Schedulers.parallel().
Use boundedElastic() whenever code may block, for example JDBC or file access. Use parallel() only for short CPU-bound, non-blocking work.
No, it affects the whole subscription chain upstream of the first publishOn. The position of publishOn does matter, since it only affects operators after it.
Only the ones you create with newSingle, newParallel, newBoundedElastic or fromExecutorService. The shared factory instances are managed by Reactor.
Schedulers is how you control threading in Project Reactor. Use parallel() for non-blocking CPU work, boundedElastic() for blocking calls, single() for serialized tasks, and immediate() when no thread hop is wanted. Place subscribeOn to pick the thread for the source, publishOn to move later stages, and use virtual time in tests.