public interface Scheduler extends Disposable
Implementations that use an underlying ExecutorService or
ScheduledExecutorService should instantiate it through a Supplier
passed through the relevant Schedulers hook
(Schedulers.decorateExecutorService(String, Supplier) or
Schedulers.decorateScheduledExecutorService(String, Supplier)).
| Modifier and Type | Interface and Description |
|---|---|
static interface |
Scheduler.Worker
A worker representing an asynchronous boundary that executes tasks in
a FIFO order, guaranteed non-concurrently with respect to each other.
|
| Modifier and Type | Field and Description |
|---|---|
static Disposable |
REJECTED
Returned by the schedule() methods if the Scheduler or the Worker has ben shut down.
|
| Modifier and Type | Method and Description |
|---|---|
Scheduler.Worker |
createWorker()
Creates a worker of this Scheduler that executed task in a strict
FIFO order, guaranteed non-concurrently with each other.
|
default void |
dispose()
Instructs this Scheduler to release all resources and reject
any new tasks to be executed.
|
Cancellation |
schedule(Runnable task)
Schedules the given task on this scheduler non-delayed execution.
|
default void |
shutdown()
Deprecated.
move the implementation to
dispose() and call dispose from shutdown.
Will be removed in 3.1.0 |
default void |
start()
Instructs this Scheduler to prepare itself for running tasks
directly or through its Workers.
|
isDisposedstatic final Disposable REJECTED
Cancellation schedule(Runnable task)
This method is safe to be called from multiple threads but there are no ordering guarantees between tasks.
task - the task to executeCancellation instance that let's one cancel this particular task.
If the Scheduler has been shut down, the REJECTED Cancellation instance is returned.Scheduler.Worker createWorker()
Once the Worker is no longer in use, one should call dispose() on it to release any resources the particular Scheduler may have used.
Tasks scheduled with this worker run in FIFO order and strictly non-concurrently, but there are no ordering guarantees between different Workers created from the same Scheduler.
default void dispose()
The operation is thread-safe but one should avoid using start() and dispose() concurrently as it would non-deterministically leave the Scheduler in either active or inactive state.
The Scheduler may choose to ignore this instruction.
dispose in interface Cancellationdispose in interface Disposabledefault void start()
The operation is thread-safe but one should avoid using start() and dispose() concurrently as it would non-deterministically leave the Scheduler in either active or inactive state.
@Deprecated default void shutdown()
dispose() and call dispose from shutdown.
Will be removed in 3.1.0The operation is thread-safe but one should avoid using start() and shutdown() concurrently as it would non-deterministically leave the Scheduler in either active or inactive state.