Package reactor.core.scheduler
Interface Schedulers.Factory
- Enclosing class:
- Schedulers
public static interface Schedulers.Factory
Public factory hook to override Schedulers behavior globally
-
Method Summary
Modifier and TypeMethodDescriptiondefault SchedulernewBoundedElastic(int threadCap, int queuedTaskCap, ThreadFactory threadFactory, int ttlSeconds) Schedulerthat dynamically creates a bounded number of ExecutorService-based Workers, reusing them once the Workers have been shut down.default SchedulernewParallel(int parallelism, ThreadFactory threadFactory) Schedulerthat hosts a fixed pool of workers and is suited for parallel work.default SchedulernewSingle(ThreadFactory threadFactory) Schedulerthat hosts a single worker and is suited for non-blocking work.default SchedulernewThreadPerTaskBoundedElastic(int threadCap, int queuedTaskCap, ThreadFactory threadFactory) Schedulerthat dynamically creates a bounded number of Workers.
-
Method Details
-
newBoundedElastic
default Scheduler newBoundedElastic(int threadCap, int queuedTaskCap, ThreadFactory threadFactory, int ttlSeconds) Schedulerthat dynamically creates a bounded number of ExecutorService-based Workers, reusing them once the Workers have been shut down. The underlying (user or daemon) threads can be evicted if idle for more thanttlSeconds.The maximum number of created thread pools is bounded by the provided
threadCap.- Parameters:
threadCap- maximum number of underlying threads to createqueuedTaskCap- maximum number of tasks to enqueue when no more threads can be created. Can beInteger.MAX_VALUEfor unbounded enqueueing.threadFactory- aThreadFactoryto use each thread initializationttlSeconds- Time-to-live for an idleScheduler.Worker- Returns:
- a new
Schedulerthat dynamically creates workers with an upper bound to the number of backing threads, reuses threads and evict idle ones
-
newThreadPerTaskBoundedElastic
default Scheduler newThreadPerTaskBoundedElastic(int threadCap, int queuedTaskCap, ThreadFactory threadFactory) Schedulerthat dynamically creates a bounded number of Workers.The maximum number of created thread pools is bounded by the provided
threadCap.The main difference between
BoundedElasticSchedulerandBoundedElasticThreadPerTaskScheduleris that underlying machinery allocates a new thread for every new task which is one of the requirements for usage withVirtualThreadsNote: for now this scheduler is available only in Java 21+ runtime
- Parameters:
threadCap- maximum number of underlying threads to createqueuedTaskCap- maximum number of tasks to enqueue when no more threads can be created. Can beInteger.MAX_VALUEfor unbounded enqueueing.threadFactory- aThreadFactoryto use each thread initialization- Returns:
- a new
Schedulerthat dynamically creates workers with an upper bound to the number of backing threads - Since:
- 3.6.0
-
newParallel
Schedulerthat hosts a fixed pool of workers and is suited for parallel work.- Parameters:
parallelism- Number of pooled workers.threadFactory- aThreadFactoryto use for the fixed initialized number ofThread- Returns:
- a new
Schedulerthat hosts a fixed pool of workers and is suited for parallel work
-
newSingle
Schedulerthat hosts a single worker and is suited for non-blocking work.- Parameters:
threadFactory- aThreadFactoryto use for the unique resource of theScheduler- Returns:
- a new
Schedulerthat hosts a single worker
-