Interface Scheduler
- All Superinterfaces:
Disposable
Implementations that use an underlying ExecutorService or
ScheduledExecutorService should decorate it with the relevant Schedulers hook
(Schedulers.decorateExecutorService(Scheduler, ScheduledExecutorService).
- Author:
- Stephane Maldini, Simon Baslé
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceA worker representing an asynchronous boundary that executes tasks.Nested classes/interfaces inherited from interface reactor.core.Disposable
Disposable.Composite, Disposable.Swap -
Method Summary
Modifier and TypeMethodDescriptionCreates a worker of this Scheduler.default voiddispose()Instructs this Scheduler to release all resources and reject any new tasks to be executed.Lazy variant ofdispose()that also allows for graceful cleanup of underlying resources.default voidinit()Instructs this Scheduler to prepare itself for running tasks directly or through itsScheduler.Workers.default longReturns the "current time" notion of this scheduler.Schedules the non-delayed execution of the given task on this scheduler.default DisposableSchedules the execution of the given task with the given delay amount.default DisposableschedulePeriodically(Runnable task, long initialDelay, long period, TimeUnit unit) Schedules a periodic execution of the given task with the given initial delay and period.default voidstart()Deprecated.Methods inherited from interface reactor.core.Disposable
isDisposed
-
Method Details
-
schedule
Schedules the non-delayed execution of the given task on this scheduler.This method is safe to be called from multiple threads but there are no ordering guarantees between tasks.
- Parameters:
task- the task to execute- Returns:
- the
Disposableinstance that lets one cancel this particular task. If theSchedulerhas been shut down, throw aRejectedExecutionException.
-
schedule
Schedules the execution of the given task with the given delay amount.This method is safe to be called from multiple threads but there are no ordering guarantees between tasks.
- Parameters:
task- the task to scheduledelay- the delay amount, non-positive values indicate non-delayed schedulingunit- the unit of measure of the delay amount- Returns:
- the
Disposablethat lets one cancel this particular delayed task, or throw aRejectedExecutionExceptionif the Scheduler is not capable of scheduling with delay.
-
schedulePeriodically
default Disposable schedulePeriodically(Runnable task, long initialDelay, long period, TimeUnit unit) Schedules a periodic execution of the given task with the given initial delay and period.This method is safe to be called from multiple threads but there are no ordering guarantees between tasks.
The periodic execution is at a fixed rate, that is, the first execution will be after the initial delay, the second after initialDelay + period, the third after initialDelay + 2 * period, and so on.
- Parameters:
task- the task to scheduleinitialDelay- the initial delay amount, non-positive values indicate non-delayed schedulingperiod- the period at which the task should be re-executedunit- the unit of measure of the delay amount- Returns:
- the
Disposablethat lets one cancel this particular delayed task, or throw aRejectedExecutionExceptionif the Scheduler is not capable of scheduling periodically.
-
now
Returns the "current time" notion of this scheduler.Implementation Note: The default implementation uses
System.currentTimeMillis()when requested with aTimeUnitofmillisecondsor coarser, andSystem.nanoTime()otherwise. As a consequence, results should not be interpreted as absolute timestamps in the latter case, only monotonicity inside the current JVM can be expected.- Parameters:
unit- the target unit of the current time- Returns:
- the current time value in the target unit of measure
-
createWorker
Scheduler.Worker createWorker()Creates a worker of this Scheduler.Once the Worker is no longer in use, one should call dispose() on it to release any resources the particular Scheduler may have used. It depends on the implementation, but Scheduler Workers should usually run tasks in FIFO order. Some implementations may entirely delegate the scheduling to an underlying structure (like an
ExecutorService).- Returns:
- the Worker instance.
-
dispose
default void dispose()Instructs this Scheduler to release all resources and reject any new tasks to be executed.The operation is thread-safe.
The Scheduler may choose to ignore this instruction.
When used in combination with
disposeGracefully()there are no guarantees that all resources will be forcefully shut down. When a graceful disposal has started, the references to the underlyingExecutors might have already been lost.- Specified by:
disposein interfaceDisposable
-
disposeGracefully
Lazy variant ofdispose()that also allows for graceful cleanup of underlying resources.It is advised to apply a
Mono.timeout(Duration)operator to the resultingMono.The returned
Monocan beretriedin case oftimeout errors. It can also be followed by a call todispose()to issue a forceful shutdown of underlying resources. -
start
Deprecated.Useinit()instead. The use of this method is discouraged. Some implementations allowed restarting a Scheduler, while others did not. One of the issues with restarting is that checkingthe disposed stateis unreliable in concurrent scenarios.Instructs this Scheduler to prepare itself for running tasks directly or through its Workers.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.
- See Also:
-
init
default void init()Instructs this Scheduler to prepare itself for running tasks directly or through itsScheduler.Workers.Implementations are encouraged to throw an exception if this method is called after the scheduler has been disposed via
dispose()ordisposeGracefully().
-
init()instead.