public class Schedulers
extends java.lang.Object
Schedulers provide various Scheduler generator useable by publishOn or subscribeOn :
fromExecutorService(ExecutorService)}. newParallel(java.lang.String)
: Optimized for fast Runnable executions single() : Optimized
for low-latency Runnable executions immediate(). | Modifier and Type | Field and Description |
|---|---|
static int |
DEFAULT_POOL_SIZE
Default number of processors available to the runtime on init (min 4)
|
| Constructor and Description |
|---|
Schedulers() |
| Modifier and Type | Method and Description |
|---|---|
static Scheduler |
computation()
Scheduler that hosts a fixed pool of single-threaded Event Loop based
workers and is suited for non blocking work. |
static Scheduler |
elastic()
Scheduler that dynamically creates ExecutorService-based Workers and caches
the thread pools, reusing them once the Workers have been shut down. |
static Scheduler |
fromExecutor(java.util.concurrent.Executor executor)
Create a
Scheduler which uses a backing Executor to schedule
Runnables for async operators. |
static Scheduler |
fromExecutor(java.util.concurrent.Executor executor,
boolean trampoline)
Create a
Scheduler which uses a backing Executor to schedule
Runnables for async operators. |
static Scheduler |
fromExecutorService(java.util.concurrent.ExecutorService executorService)
Create a
Scheduler which uses a backing ExecutorService to schedule
Runnables for async operators. |
static Scheduler |
immediate()
Executes tasks on the caller's thread immediately.
|
static Scheduler |
newComputation(int parallelism,
int bufferSize,
java.util.concurrent.ThreadFactory threadFactory)
Scheduler that hosts a fixed pool of single-threaded Event Loop based
workers and is suited for non blocking work. |
static Scheduler |
newComputation(java.lang.String name)
Scheduler that hosts a fixed pool of single-threaded Event Loop based
workers and is suited for non blocking work. |
static Scheduler |
newComputation(java.lang.String name,
int parallelism)
Scheduler that hosts a fixed pool of single-threaded Event Loop based
workers and is suited for non blocking work. |
static Scheduler |
newComputation(java.lang.String name,
int parallelism,
boolean daemon)
Scheduler that hosts a fixed pool of single-threaded Event Loop based
workers and is suited for non blocking work. |
static Scheduler |
newComputation(java.lang.String name,
int parallelism,
int bufferSize)
Scheduler that hosts a fixed pool of single-threaded Event Loop based
workers and is suited for non blocking work. |
static Scheduler |
newComputation(java.lang.String name,
int parallelism,
int bufferSize,
boolean daemon)
Scheduler that hosts a fixed pool of single-threaded Event Loop based
workers and is suited for non blocking work. |
static Scheduler |
newElastic(int ttlSeconds,
java.util.concurrent.ThreadFactory threadFactory)
Scheduler that dynamically creates ExecutorService-based Workers and caches
the thread pools, reusing them once the Workers have been shut down. |
static Scheduler |
newElastic(java.lang.String name)
Scheduler that dynamically creates ExecutorService-based Workers and caches
the thread pools, reusing them once the Workers have been shut down. |
static Scheduler |
newElastic(java.lang.String name,
int ttlSeconds)
Scheduler that dynamically creates ExecutorService-based Workers and caches
the thread pools, reusing them once the Workers have been shut down. |
static Scheduler |
newElastic(java.lang.String name,
int ttlSeconds,
boolean daemon)
Scheduler that dynamically creates ExecutorService-based Workers and caches
the thread pools, reusing them once the Workers have been shut down. |
static Scheduler |
newParallel(int parallelism,
java.util.concurrent.ThreadFactory threadFactory)
Scheduler that hosts a fixed pool of single-threaded ExecutorService-based
workers and is suited for parallel work. |
static Scheduler |
newParallel(java.lang.String name)
Scheduler that hosts a fixed pool of single-threaded ExecutorService-based
workers and is suited for parallel work. |
static Scheduler |
newParallel(java.lang.String name,
int parallelism)
Scheduler that hosts a fixed pool of single-threaded ExecutorService-based
workers and is suited for parallel work. |
static Scheduler |
newParallel(java.lang.String name,
int parallelism,
boolean daemon)
Scheduler that hosts a fixed pool of single-threaded ExecutorService-based
workers and is suited for parallel work. |
static Scheduler |
newSingle(java.lang.String name)
Scheduler that hosts a single-threaded ExecutorService-based worker and is
suited for parallel work. |
static Scheduler |
newSingle(java.lang.String name,
boolean daemon)
Scheduler that hosts a single-threaded ExecutorService-based worker and is
suited for parallel work. |
static Scheduler |
newSingle(java.util.concurrent.ThreadFactory threadFactory)
Scheduler that hosts a single-threaded ExecutorService-based worker and is
suited for parallel work. |
static TimedScheduler |
newTimer(java.lang.String name)
Create a new
TimedScheduler backed by a single threaded
ScheduledExecutorService. |
static TimedScheduler |
newTimer(java.lang.String name,
boolean daemon)
Create a new
TimedScheduler backed by a single threaded
ScheduledExecutorService. |
static TimedScheduler |
newTimer(java.util.concurrent.ThreadFactory threadFactory)
Create a new
TimedScheduler backed by a single threaded
ScheduledExecutorService. |
static Scheduler |
parallel()
Scheduler that hosts a fixed pool of single-threaded ExecutorService-based
workers and is suited for parallel work. |
static void |
setComputationFactory(java.lang.Class<?> factoryClass)
Assign a
newComputation(java.lang.String) factory using the matching method signature in
the target class. |
static void |
shutdownNow()
Clear any cached
Scheduler and call shutdown on them. |
static Scheduler |
single()
Scheduler that hosts a single-threaded ExecutorService-based worker and is
suited for parallel work. |
static Scheduler |
single(Scheduler original)
Wraps a single worker of some other
Scheduler and
provides Scheduler.Worker services on top of it. |
static TimedScheduler |
timer()
Create or reuse a hash-wheel based
TimedScheduler with a resolution of 50MS
All times will rounded up to the closest multiple of this resolution. |
public static final int DEFAULT_POOL_SIZE
Runtime.availableProcessors()public static Scheduler computation()
Scheduler that hosts a fixed pool of single-threaded Event Loop based
workers and is suited for non blocking work.Scheduler that hosts a fixed pool of single-threaded
Event-Loop based workerspublic static Scheduler fromExecutor(java.util.concurrent.Executor executor)
Scheduler which uses a backing Executor to schedule
Runnables for async operators.executor - an ExecutorSchedulerpublic static Scheduler fromExecutor(java.util.concurrent.Executor executor, boolean trampoline)
Scheduler which uses a backing Executor to schedule
Runnables for async operators.public static Scheduler fromExecutorService(java.util.concurrent.ExecutorService executorService)
Scheduler which uses a backing ExecutorService to schedule
Runnables for async operators.executorService - an ExecutorServiceSchedulerpublic static Scheduler elastic()
Scheduler that dynamically creates ExecutorService-based Workers and caches
the thread pools, reusing them once the Workers have been shut down.
The maximum number of created thread pools is unbounded.
The default time-to-live for unused thread pools is 60 seconds, use the appropriate factory to set a different value.
This scheduler is not restartable.
Scheduler that hosts a fixed pool of single-threaded
ExecutorService-based workers and is suited for parallel workpublic static Scheduler immediate()
Schedulerpublic static Scheduler newComputation(java.lang.String name)
Scheduler that hosts a fixed pool of single-threaded Event Loop based
workers and is suited for non blocking work.name - Thread prefixScheduler that hosts a fixed pool of single-threaded
ExecutorService-based workers and is suited for parallel workpublic static Scheduler newComputation(java.lang.String name, int parallelism)
Scheduler that hosts a fixed pool of single-threaded Event Loop based
workers and is suited for non blocking work.name - Thread prefixparallelism - Number of pooled workers.Scheduler that hosts a fixed pool of single-threaded
ExecutorService-based workers and is suited for parallel workpublic static Scheduler newComputation(java.lang.String name, int parallelism, int bufferSize)
Scheduler that hosts a fixed pool of single-threaded Event Loop based
workers and is suited for non blocking work.name - Thread prefixparallelism - Number of pooled workers.bufferSize - backlog size to be used by event loops.Scheduler that hosts a fixed pool of single-threaded
ExecutorService-based workers and is suited for parallel workpublic static Scheduler newComputation(java.lang.String name, int parallelism, boolean daemon)
Scheduler that hosts a fixed pool of single-threaded Event Loop based
workers and is suited for non blocking work.name - Thread prefixparallelism - Number of pooled workers.daemon - false if the Scheduler requires an explicit Scheduler.shutdown() to exit the VM.Scheduler that hosts a fixed pool of single-threaded
ExecutorService-based workers and is suited for parallel workpublic static Scheduler newComputation(java.lang.String name, int parallelism, int bufferSize, boolean daemon)
Scheduler that hosts a fixed pool of single-threaded Event Loop based
workers and is suited for non blocking work.name - Thread prefixparallelism - Number of pooled workers.bufferSize - backlog size to be used by event loops.daemon - false if the Scheduler requires an explicit Scheduler.shutdown() to exit the VM.Scheduler that hosts a fixed pool of single-threaded
ExecutorService-based workers and is suited for parallel workpublic static Scheduler newComputation(int parallelism, int bufferSize, java.util.concurrent.ThreadFactory threadFactory)
Scheduler that hosts a fixed pool of single-threaded Event Loop based
workers and is suited for non blocking work.parallelism - Number of pooled workers.bufferSize - backlog size to be used by event loops.threadFactory - a ThreadFactory to use for the unique thread of the
SchedulerScheduler that hosts a fixed pool of single-threaded
ExecutorService-based workers and is suited for parallel workpublic static Scheduler newElastic(java.lang.String name)
Scheduler that dynamically creates ExecutorService-based Workers and caches
the thread pools, reusing them once the Workers have been shut down.
The maximum number of created thread pools is unbounded.
The default time-to-live for unused thread pools is 60 seconds, use the appropriate factory to set a different value.
This scheduler is not restartable.
name - Thread prefixScheduler that hosts a fixed pool of single-threaded
ExecutorService-based workers and is suited for parallel workpublic static Scheduler newElastic(java.lang.String name, int ttlSeconds)
Scheduler that dynamically creates ExecutorService-based Workers and caches
the thread pools, reusing them once the Workers have been shut down.
The maximum number of created thread pools is unbounded.
This scheduler is not restartable.
name - Thread prefixttlSeconds - Time-to-live for an idle Scheduler.WorkerScheduler that hosts a fixed pool of single-threaded
ExecutorService-based workers and is suited for parallel workpublic static Scheduler newElastic(java.lang.String name, int ttlSeconds, boolean daemon)
Scheduler that dynamically creates ExecutorService-based Workers and caches
the thread pools, reusing them once the Workers have been shut down.
The maximum number of created thread pools is unbounded.
This scheduler is not restartable.
name - Thread prefixttlSeconds - Time-to-live for an idle Scheduler.Workerdaemon - false if the Scheduler requires an explicit Scheduler.shutdown() to exit the VM.Scheduler that hosts a fixed pool of single-threaded
ExecutorService-based workers and is suited for parallel workpublic static Scheduler newElastic(int ttlSeconds, java.util.concurrent.ThreadFactory threadFactory)
Scheduler that dynamically creates ExecutorService-based Workers and caches
the thread pools, reusing them once the Workers have been shut down.
The maximum number of created thread pools is unbounded.
This scheduler is not restartable.
ttlSeconds - Time-to-live for an idle Scheduler.WorkerthreadFactory - a ThreadFactory to use for the unique thread of the
SchedulerScheduler that dynamically creates ExecutorService-based
Workers and caches the thread pools, reusing them once the Workers have been shut
down.public static Scheduler newParallel(java.lang.String name)
Scheduler that hosts a fixed pool of single-threaded ExecutorService-based
workers and is suited for parallel work.name - Thread prefixScheduler that hosts a fixed pool of single-threaded
ExecutorService-based workers and is suited for parallel workpublic static Scheduler newParallel(java.lang.String name, int parallelism)
Scheduler that hosts a fixed pool of single-threaded ExecutorService-based
workers and is suited for parallel work.name - Thread prefixparallelism - Number of pooled workers.Scheduler that hosts a fixed pool of single-threaded
ExecutorService-based workers and is suited for parallel workpublic static Scheduler newParallel(java.lang.String name, int parallelism, boolean daemon)
Scheduler that hosts a fixed pool of single-threaded ExecutorService-based
workers and is suited for parallel work.name - Thread prefixparallelism - Number of pooled workers.daemon - false if the Scheduler requires an explicit Scheduler.shutdown() to exit the VM.Scheduler that hosts a fixed pool of single-threaded
ExecutorService-based workers and is suited for parallel workpublic static Scheduler newParallel(int parallelism, java.util.concurrent.ThreadFactory threadFactory)
Scheduler that hosts a fixed pool of single-threaded ExecutorService-based
workers and is suited for parallel work.public static Scheduler newSingle(java.lang.String name)
Scheduler that hosts a single-threaded ExecutorService-based worker and is
suited for parallel work.name - Component and thread name prefixScheduler that hosts a single-threaded ExecutorService-based
workerpublic static Scheduler newSingle(java.lang.String name, boolean daemon)
Scheduler that hosts a single-threaded ExecutorService-based worker and is
suited for parallel work.name - Component and thread name prefixdaemon - false if the Scheduler requires an explicit Scheduler.shutdown() to exit the VM.Scheduler that hosts a single-threaded ExecutorService-based
workerpublic static Scheduler newSingle(java.util.concurrent.ThreadFactory threadFactory)
Scheduler that hosts a single-threaded ExecutorService-based worker and is
suited for parallel work.public static TimedScheduler newTimer(java.lang.String name)
TimedScheduler backed by a single threaded
ScheduledExecutorService.name - timer thread prefixTimedSchedulerpublic static TimedScheduler newTimer(java.lang.String name, boolean daemon)
TimedScheduler backed by a single threaded
ScheduledExecutorService.name - Component and thread name prefixdaemon - false if the Scheduler requires an explicit Scheduler.shutdown() to exit the VM.TimedSchedulerpublic static TimedScheduler newTimer(java.util.concurrent.ThreadFactory threadFactory)
TimedScheduler backed by a single threaded
ScheduledExecutorService.threadFactory - a ThreadFactory to use for the unique thread of the
SchedulerTimedSchedulerpublic static Scheduler parallel()
Scheduler that hosts a fixed pool of single-threaded ExecutorService-based
workers and is suited for parallel work.Scheduler that hosts a fixed pool of single-threaded ExecutorService-based
workerspublic static void setComputationFactory(java.lang.Class<?> factoryClass)
newComputation(java.lang.String) factory using the matching method signature in
the target class.factoryClass - an arbitrary type with static methods matching newComputation(java.lang.String) signature(s).public static void shutdownNow()
Scheduler and call shutdown on them.public static Scheduler single()
Scheduler that hosts a single-threaded ExecutorService-based worker and is
suited for parallel work. Will cache the returned schedulers for subsequent single() calls until shutdown.Scheduler that hosts a single-threaded
ExecutorService-based workerpublic static Scheduler single(Scheduler original)
Scheduler and
provides Scheduler.Worker services on top of it.
Use the Scheduler.shutdown() to release the wrapped worker.
original - a Scheduler to call upon to get the single
Scheduler.WorkerScheduler consistently returning a same worker from a
source Schedulerpublic static TimedScheduler timer()
TimedScheduler with a resolution of 50MS
All times will rounded up to the closest multiple of this resolution.TimedScheduler