public abstract class Scheduler
extends java.lang.Object
Scheduler
is an object that specifies an API for scheduling
units of work with or without delays or periodically.
You can get common instances of this class in Schedulers
.Modifier and Type | Class and Description |
---|---|
static class |
Scheduler.Worker
Sequential Scheduler for executing actions on a single thread or event loop.
|
Constructor and Description |
---|
Scheduler() |
Modifier and Type | Method and Description |
---|---|
static long |
clockDriftTolerance()
Returns the clock drift tolerance in nanoseconds.
|
abstract Scheduler.Worker |
createWorker()
Retrieves or creates a new
Scheduler.Worker that represents serial execution of actions. |
long |
now(java.util.concurrent.TimeUnit unit)
Returns the 'current time' of the Scheduler in the specified time unit.
|
Disposable |
scheduleDirect(java.lang.Runnable run)
Schedules the given task on this scheduler non-delayed execution.
|
Disposable |
scheduleDirect(java.lang.Runnable run,
long delay,
java.util.concurrent.TimeUnit unit)
Schedules the execution of the given task with the given delay amount.
|
Disposable |
schedulePeriodicallyDirect(java.lang.Runnable run,
long initialDelay,
long period,
java.util.concurrent.TimeUnit unit)
Schedules a periodic execution of the given task with the given initial delay and period.
|
void |
shutdown()
Instructs the Scheduler instance to stop threads
and stop accepting tasks on any outstanding Workers.
|
void |
start()
Allows the Scheduler instance to start threads
and accept tasks on them.
|
public static long clockDriftTolerance()
Related system property: rx2.scheduler.drift-tolerance
in minutes
public abstract Scheduler.Worker createWorker()
Scheduler.Worker
that represents serial execution of actions.
When work is completed it should be unsubscribed using Disposable.dispose()
.
Work on a Scheduler.Worker
is guaranteed to be sequential.
public long now(java.util.concurrent.TimeUnit unit)
unit
- the time unitpublic void start()
Implementations should make sure the call is idempotent and thread-safe.
public void shutdown()
Implementations should make sure the call is idempotent and thread-safe.
public Disposable scheduleDirect(java.lang.Runnable run)
This method is safe to be called from multiple threads but there are no ordering guarantees between tasks.
run
- the task to executepublic Disposable scheduleDirect(java.lang.Runnable run, long delay, java.util.concurrent.TimeUnit unit)
This method is safe to be called from multiple threads but there are no ordering guarantees between tasks.
run
- the task to scheduledelay
- the delay amount, non-positive values indicate non-delayed schedulingunit
- the unit of measure of the delay amountpublic Disposable schedulePeriodicallyDirect(java.lang.Runnable run, long initialDelay, long period, java.util.concurrent.TimeUnit unit)
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.
run
- 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