Class Schedulers
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Schedulerprivate static final AtomicReference<Schedulers> private final Schedulerprivate final Scheduler -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic SchedulerCreates and returns aSchedulerintended for computational work.static SchedulerConverts anExecutorinto a new Scheduler instance.private static Schedulersstatic SchedulerCreates and returns aSchedulerthat executes work immediately on the current thread.static Schedulerio()Creates and returns aSchedulerintended for IO-bound work.static Schedulerstatic voidreset()Resets the currentSchedulersinstance.static voidshutdown()Shuts down those standard Schedulers which support the SchedulerLifecycle interface.(package private) voidStart the instance-specific schedulers.static voidstart()Starts those standard Schedulers which support the SchedulerLifecycle interface.(package private) voidStart the instance-specific schedulers.static TestSchedulertest()Creates and returns aTestScheduler, which is useful for debugging.static SchedulerCreates and returns aSchedulerthat queues work on the current thread to be executed after the current work completes.
-
Field Details
-
computationScheduler
-
ioScheduler
-
newThreadScheduler
-
INSTANCE
-
-
Constructor Details
-
Schedulers
private Schedulers()
-
-
Method Details
-
getInstance
-
immediate
Creates and returns aSchedulerthat executes work immediately on the current thread.- Returns:
- a
Schedulerthat executes work immediately
-
trampoline
Creates and returns aSchedulerthat queues work on the current thread to be executed after the current work completes.- Returns:
- a
Schedulerthat queues work on the current thread
-
newThread
Creates and returns aSchedulerthat creates a newThreadfor each unit of work.Unhandled errors will be delivered to the scheduler Thread's
Thread.UncaughtExceptionHandler.- Returns:
- a
Schedulerthat creates new threads
-
computation
Creates and returns aSchedulerintended for computational work.This can be used for event-loops, processing callbacks and other computational work.
Do not perform IO-bound work on this scheduler. Use
io()instead.Unhandled errors will be delivered to the scheduler Thread's
Thread.UncaughtExceptionHandler.- Returns:
- a
Schedulermeant for computation-bound work
-
io
Creates and returns aSchedulerintended for IO-bound work.The implementation is backed by an
Executorthread-pool that will grow as needed.This can be used for asynchronously performing blocking IO.
Do not perform computational work on this scheduler. Use
computation()instead.Unhandled errors will be delivered to the scheduler Thread's
Thread.UncaughtExceptionHandler.- Returns:
- a
Schedulermeant for IO-bound work
-
test
Creates and returns aTestScheduler, which is useful for debugging. It allows you to test schedules of events by manually advancing the clock at whatever pace you choose.- Returns:
- a
TestSchedulermeant for debugging
-
from
Converts anExecutorinto a new Scheduler instance.- Parameters:
executor- the executor to wrap- Returns:
- the new Scheduler wrapping the Executor
-
reset
Resets the currentSchedulersinstance. This will re-init the cached schedulers on the next usage, which can be useful in testing. -
start
public static void start()Starts those standard Schedulers which support the SchedulerLifecycle interface.The operation is idempotent and threadsafe.
-
shutdown
public static void shutdown()Shuts down those standard Schedulers which support the SchedulerLifecycle interface.The operation is idempotent and threadsafe.
-
startInstance
void startInstance()Start the instance-specific schedulers. -
shutdownInstance
void shutdownInstance()Start the instance-specific schedulers.
-