Top Description Inners Methods
reactor.core.scheduler

public Interface Scheduler

extends Disposable
Known Direct Implementers
reactor.core.scheduler.Schedulers.CachedScheduler, reactor.core.scheduler.SingleScheduler, reactor.core.scheduler.SingleWorkerScheduler, reactor.core.scheduler.ThreadPerTaskBoundedElasticScheduler, reactor.core.scheduler.BoundedElasticScheduler, reactor.core.scheduler.DelegateServiceScheduler, reactor.core.scheduler.ExecutorScheduler, reactor.core.scheduler.ImmediateScheduler, reactor.core.scheduler.ParallelScheduler
Imports
reactor.core.Disposable, .Exceptions, reactor.core.publisher.Mono, java.time.Duration, java.util.concurrent.ExecutorService, .RejectedExecutionException, .ScheduledExecutorService, .TimeUnit

Provides an abstract asynchronous boundary to operators.

Implementations that use an underlying ExecutorService or ScheduledExecutorService should decorate it with the relevant Schedulers hook (Schedulers#decorateExecutorService(Scheduler, ScheduledExecutorService).

Authors
Stephane Maldini, Simon Baslé

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static interface
Scheduler.Worker

A worker representing an asynchronous boundary that executes tasks.

Method Summary

Modifier and TypeMethod and Description
public Scheduler.Worker

Returns:

the Worker instance.
createWorker
()

Creates a worker of this Scheduler.

public default void
dispose()

Implements reactor.core.Disposable.dispose.

Instructs this Scheduler to release all resources and reject any new tasks to be executed.
public default Mono<Void>

Returns:

Mono which upon subscription initiates the graceful dispose procedure. If the disposal is successful, the returned Mono completes without an error.
disposeGracefully
()

Lazy variant of dispose() that also allows for graceful cleanup of underlying resources.

public default void
init()

Instructs this Scheduler to prepare itself for running tasks directly or through its Workers.

public default long

Returns:

the current time value in the target unit of measure
now
(TimeUnit
the target unit of the current time
unit
)

Returns the "current time" notion of this scheduler.

public Disposable

Returns:

the Disposable instance that let's one cancel this particular task. If the Scheduler has been shut down, throw a RejectedExecutionException.
schedule
(Runnable
the task to execute
task
)

Schedules the non-delayed execution of the given task on this scheduler.

public default Disposable

Returns:

the Disposable that let's one cancel this particular delayed task, or throw a RejectedExecutionException if the Scheduler is not capable of scheduling with delay.
schedule
(Runnable
the task to schedule
task
,
long
the delay amount, non-positive values indicate non-delayed scheduling
delay
,
TimeUnit
the unit of measure of the delay amount
unit
)

Schedules the execution of the given task with the given delay amount.

public default Disposable

Returns:

the Disposable that let's one cancel this particular delayed task, or throw a RejectedExecutionException if the Scheduler is not capable of scheduling periodically.
schedulePeriodically
(Runnable
the task to schedule
task
,
long
the initial delay amount, non-positive values indicate non-delayed scheduling
initialDelay
,
long
the period at which the task should be re-executed
period
,
TimeUnit
the unit of measure of the delay amount
unit
)

Schedules a periodic execution of the given task with the given initial delay and period.

public default void
start()

Deprecated Use init() instead.
Instructs this Scheduler to prepare itself for running tasks directly or through its Workers.
Inherited from reactor.core.Disposable:
isDisposed

Method Detail

createWorkerback to summary
public 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:Scheduler.Worker

the Worker instance.

disposeback to summary
public default void dispose()

Implements reactor.core.Disposable.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 shutdown. When a graceful disposal has started, the references to the underlying java.util.concurrent.Executors might have already been lost.

disposeGracefullyback to summary
public default Mono<Void> disposeGracefully()

Lazy variant of dispose() that also allows for graceful cleanup of underlying resources.

It is advised to apply a Mono#timeout(Duration) operator to the resulting Mono.

The returned Mono can be retried in case of timeout errors. It can also be followed by a call to dispose() to issue a forceful shutdown of underlying resources.

Returns:Mono<Void>

Mono which upon subscription initiates the graceful dispose procedure. If the disposal is successful, the returned Mono completes without an error.

initback to summary
public default void init()

Instructs this Scheduler to prepare itself for running tasks directly or through its Workers.

Implementations are encouraged to throw an exception if this method is called after the scheduler has been disposed via dispose() or disposeGracefully().

nowback to summary
public default long now(TimeUnit unit)

Returns the "current time" notion of this scheduler.

Implementation Note

The default implementation uses System#currentTimeMillis() when requested with a TimeUnit of milliseconds or coarser, and System#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:TimeUnit

the target unit of the current time

Returns:long

the current time value in the target unit of measure

scheduleback to summary
public Disposable schedule(Runnable task)

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:Runnable

the task to execute

Returns:Disposable

the Disposable instance that let's one cancel this particular task. If the Scheduler has been shut down, throw a RejectedExecutionException.

scheduleback to summary
public default Disposable schedule(Runnable task, long delay, TimeUnit unit)

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:Runnable

the task to schedule

delay:long

the delay amount, non-positive values indicate non-delayed scheduling

unit:TimeUnit

the unit of measure of the delay amount

Returns:Disposable

the Disposable that let's one cancel this particular delayed task, or throw a RejectedExecutionException if the Scheduler is not capable of scheduling with delay.

schedulePeriodicallyback to summary
public 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:Runnable

the task to schedule

initialDelay:long

the initial delay amount, non-positive values indicate non-delayed scheduling

period:long

the period at which the task should be re-executed

unit:TimeUnit

the unit of measure of the delay amount

Returns:Disposable

the Disposable that let's one cancel this particular delayed task, or throw a RejectedExecutionException if the Scheduler is not capable of scheduling periodically.

startback to summary
public default void start()

Deprecated

Use init() 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 checking the disposed state is 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.

Annotations
@Deprecated
See Also
init()
reactor.core.scheduler back to summary

public Interface Scheduler.Worker

extends Disposable
Known Direct Implementers
reactor.core.scheduler.ExecutorScheduler.ExecutorSchedulerWorker, reactor.core.scheduler.ExecutorScheduler.ExecutorSchedulerTrampolineWorker, reactor.core.scheduler.ExecutorServiceWorker, reactor.core.scheduler.ImmediateScheduler.ImmediateSchedulerWorker

A worker representing an asynchronous boundary that executes tasks.
Authors
Stephane Maldini, Simon Baslé

Method Summary

Modifier and TypeMethod and Description
public Disposable

Returns:

the Disposable instance that let's one cancel this particular task. If the Scheduler has been shut down, a RejectedExecutionException is thrown.
schedule
(Runnable
the task to schedule
task
)

Schedules the task for immediate execution on this worker.

public default Disposable

Returns:

the Disposable that let's one cancel this particular delayed task, or throw a RejectedExecutionException if the Worker is not capable of scheduling with delay.
schedule
(Runnable
the task to schedule
task
,
long
the delay amount, non-positive values indicate non-delayed scheduling
delay
,
TimeUnit
the unit of measure of the delay amount
unit
)

Schedules the execution of the given task with the given delay amount.

public default Disposable

Returns:

the Disposable that let's one cancel this particular delayed task, or throw a RejectedExecutionException if the Worker is not capable of scheduling periodically.
schedulePeriodically
(Runnable
the task to schedule
task
,
long
the initial delay amount, non-positive values indicate non-delayed scheduling
initialDelay
,
long
the period at which the task should be re-executed
period
,
TimeUnit
the unit of measure of the delay amount
unit
)

Schedules a periodic execution of the given task with the given initial delay and period.

Inherited from reactor.core.Disposable:
disposeisDisposed

Method Detail

scheduleback to summary
public Disposable schedule(Runnable task)

Schedules the task for immediate execution on this worker.

Parameters
task:Runnable

the task to schedule

Returns:Disposable

the Disposable instance that let's one cancel this particular task. If the Scheduler has been shut down, a RejectedExecutionException is thrown.

scheduleback to summary
public default Disposable schedule(Runnable task, long delay, TimeUnit unit)

Schedules the execution of the given task with the given delay amount.

This method is safe to be called from multiple threads and tasks are executed in some total order. Two tasks scheduled at a same time with the same delay will be ordered in FIFO order if the schedule() was called from the same thread or in arbitrary order if the schedule() was called from different threads.

Parameters
task:Runnable

the task to schedule

delay:long

the delay amount, non-positive values indicate non-delayed scheduling

unit:TimeUnit

the unit of measure of the delay amount

Returns:Disposable

the Disposable that let's one cancel this particular delayed task, or throw a RejectedExecutionException if the Worker is not capable of scheduling with delay.

schedulePeriodicallyback to summary
public 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.

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:Runnable

the task to schedule

initialDelay:long

the initial delay amount, non-positive values indicate non-delayed scheduling

period:long

the period at which the task should be re-executed

unit:TimeUnit

the unit of measure of the delay amount

Returns:Disposable

the Disposable that let's one cancel this particular delayed task, or throw a RejectedExecutionException if the Worker is not capable of scheduling periodically.