Top Description Inners Fields Constructors Methods
io.reactivex.rxjava3.core

public abstract Class Scheduler

extends Object
Class Inheritance
Known Direct Subclasses
io.reactivex.rxjava3.internal.schedulers.ComputationScheduler, io.reactivex.rxjava3.internal.schedulers.ExecutorScheduler, io.reactivex.rxjava3.internal.schedulers.ImmediateThinScheduler, io.reactivex.rxjava3.internal.schedulers.IoScheduler, io.reactivex.rxjava3.internal.schedulers.NewThreadScheduler, io.reactivex.rxjava3.internal.schedulers.SchedulerWhen, io.reactivex.rxjava3.internal.schedulers.SingleScheduler, io.reactivex.rxjava3.internal.schedulers.TrampolineScheduler, io.reactivex.rxjava3.schedulers.TestScheduler
Imports
java.util.Objects, java.util.concurrent.TimeUnit, io.reactivex.rxjava3.annotations.*, io.reactivex.rxjava3.disposables.Disposable, io.reactivex.rxjava3.functions.Function, io.reactivex.rxjava3.internal.disposables.*, io.reactivex.rxjava3.internal.schedulers.*, io.reactivex.rxjava3.plugins.RxJavaPlugins, io.reactivex.rxjava3.schedulers.SchedulerRunnableIntrospection

A Scheduler is an object that specifies an API for scheduling units of work provided in the form of Runnables to be executed without delay (effectively as soon as possible), after a specified time delay or periodically and represents an abstraction over an asynchronous boundary that ensures these units of work get executed by some underlying task-execution scheme (such as custom Threads, event loop, Executor or Actor system) with some uniform properties and guarantees regardless of the particular underlying scheme.

You can get various standard, RxJava-specific instances of this class via the static methods of the io.reactivex.rxjava3.schedulers.Schedulers utility class.

The so-called Workers of a Scheduler can be created via the createWorker() method which allow the scheduling of multiple Runnable tasks in an isolated manner. Runnable tasks scheduled on a Worker are guaranteed to be executed sequentially and in a non-overlapping fashion. Non-delayed Runnable tasks are guaranteed to execute in a First-In-First-Out order but their execution may be interleaved with delayed tasks. In addition, outstanding or running tasks can be cancelled together via Worker#dispose() without affecting any other Worker instances of the same Scheduler.

Implementations of the scheduleDirect and Worker#schedule methods are encouraged to call the io.reactivex.rxjava3.plugins.RxJavaPlugins#onSchedule(Runnable) method to allow a scheduler hook to manipulate (wrap or replace) the original Runnable task before it is submitted to the underlying task-execution scheme.

The default implementations of the scheduleDirect methods provided by this abstract class delegate to the respective schedule methods in the Worker instance created via createWorker() for each individual Runnable task submitted. Implementors of this class are encouraged to provide a more efficient direct scheduling implementation to avoid the time and memory overhead of creating such Workers for every task. This delegation is done via special wrapper instances around the original Runnable before calling the respective Worker.schedule method. Note that this can lead to multiple RxJavaPlugins.onSchedule calls and potentially multiple hooks applied. Therefore, the default implementations of scheduleDirect (and the Worker#schedulePeriodically(Runnable, long, long, TimeUnit)) wrap the incoming Runnable into a class that implements the io.reactivex.rxjava3.schedulers.SchedulerRunnableIntrospection interface which can grant access to the original or hooked Runnable, thus, a repeated RxJavaPlugins.onSchedule can detect the earlier hook and not apply a new one over again.

The default implementation of now(TimeUnit) and Worker#now(TimeUnit) methods to return current System#currentTimeMillis() value in the desired time unit, unless rx3.scheduler.use-nanotime (boolean) is set. When the property is set to true, the method uses System#nanoTime() as its basis instead. Custom Scheduler implementations can override this to provide specialized time accounting (such as virtual time to be advanced programmatically). Note that operators requiring a Scheduler may rely on either of the now() calls provided by Scheduler or Worker respectively, therefore, it is recommended they represent a logically consistent source of the current time.

The default implementation of the Worker#schedulePeriodically(Runnable, long, long, TimeUnit) method uses the Worker#schedule(Runnable, long, TimeUnit) for scheduling the Runnable task periodically. The algorithm calculates the next absolute time when the task should run again and schedules this execution based on the relative time between it and Worker#now(TimeUnit). However, drifts or changes in the system clock could affect this calculation either by scheduling subsequent runs too frequently or too far apart. Therefore, the default implementation uses the clockDriftTolerance() value (set via rx3.scheduler.drift-tolerance and rx3.scheduler.drift-tolerance-unit) to detect a drift in Worker#now(TimeUnit) and re-adjust the absolute/relative time calculation accordingly.

The default implementations of start() and shutdown() do nothing and should be overridden if the underlying task-execution scheme supports stopping and restarting itself.

If the Scheduler is shut down or a Worker is disposed, the schedule methods should return the Disposable#disposed() singleton instance indicating the shut down/disposed state to the caller. Since the shutdown or dispose can happen from any thread, the schedule implementations should make best effort to cancel tasks immediately after those tasks have been submitted to the underlying task-execution scheme if the shutdown/dispose was detected after this submission.

All methods on the Scheduler and Worker classes should be thread safe.

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class
pack-priv static class
public abstract static class
Scheduler.Worker

Represents an isolated, sequential worker of a parent Scheduler for executing Runnable tasks on an underlying task-execution scheme (such as custom Threads, event loop, Executor or Actor system).

Field Summary

Modifier and TypeField and Description
pack-priv static final long
CLOCK_DRIFT_TOLERANCE_NANOSECONDS

The tolerance for a clock drift in nanoseconds where the periodic scheduler will rebase.

pack-priv static boolean
IS_DRIFT_USE_NANOTIME

Value representing whether to use System#nanoTime(), or default as clock for now(TimeUnit) and Scheduler.Worker#now(TimeUnit).

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static long

Returns:

the tolerance in nanoseconds
clockDriftTolerance
()

Returns the clock drift tolerance in nanoseconds.

pack-priv static long

Returns:

the time amount in nanoseconds
computeClockDrift
(long
the time value
time
,
String
the time unit string
timeUnit
)

Returns the clock drift tolerance in nanoseconds based on the input selection.

pack-priv static long

Returns:

the 'current time' in given unit
computeNow
(TimeUnit
the time unit
unit
)

Returns the current clock time depending on state of Scheduler#IS_DRIFT_USE_NANOTIME in given unit

By default System#currentTimeMillis() will be used as the clock.

public abstract @NonNull Scheduler.Worker

Returns:

a Worker representing a serial queue of actions to be executed
createWorker
()

Retrieves or creates a new Scheduler.Worker that represents sequential execution of actions.

public long

Returns:

the 'current time'
now
(@NonNull TimeUnit
the time unit
unit
)

Returns the 'current time' of the Scheduler in the specified time unit.

public @NonNull Disposable

Returns:

the Disposable instance that let's one cancel this particular task.
scheduleDirect
(@NonNull Runnable
the task to execute
run
)

Schedules the given task on this Scheduler without any time delay.

public @NonNull Disposable

Returns:

the Disposable that let's one cancel this particular delayed task.
scheduleDirect
(@NonNull Runnable
the task to schedule
run
,
long
the delay amount, non-positive values indicate non-delayed scheduling
delay
,
@NonNull TimeUnit
the unit of measure of the delay amount
unit
)

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

public @NonNull Disposable

Returns:

the Disposable that let's one cancel this particular delayed task.
schedulePeriodicallyDirect
(@NonNull Runnable
the task to schedule
run
,
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
,
@NonNull TimeUnit
the unit of measure of the delay amount
unit
)

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

public void
shutdown()

Instructs the Scheduler instance to stop threads, stop accepting tasks on any outstanding Worker instances and clean up any associated resources with this Scheduler.

public void
start()

Allows the Scheduler instance to start threads and accept tasks on them.

public <
a Scheduler and a Subscription
S extends Scheduler & Disposable
>
S

Returns:

the Scheduler with the customized execution behavior
when
(@NonNull Function<Flowable<Flowable<Completable>>, Completable>
the function that takes a two-level nested Flowable sequence of a Completable and returns the Completable that will be subscribed to and should trigger the execution of the scheduled Actions.
combine
)

Allows the use of operators for controlling the timing around when actions scheduled on workers are actually done.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

CLOCK_DRIFT_TOLERANCE_NANOSECONDSback to summary
pack-priv static final long CLOCK_DRIFT_TOLERANCE_NANOSECONDS

The tolerance for a clock drift in nanoseconds where the periodic scheduler will rebase.

Associated system parameters:

  • rx3.scheduler.drift-tolerance, long, default 15
  • rx3.scheduler.drift-tolerance-unit, string, default minutes, supports seconds and milliseconds.
IS_DRIFT_USE_NANOTIMEback to summary
pack-priv static boolean IS_DRIFT_USE_NANOTIME

Value representing whether to use System#nanoTime(), or default as clock for now(TimeUnit) and Scheduler.Worker#now(TimeUnit).

Associated system parameter:

  • rx3.scheduler.use-nanotime, boolean, default false

Constructor Detail

Schedulerback to summary
public Scheduler()

Method Detail

clockDriftToleranceback to summary
public static long clockDriftTolerance()

Returns the clock drift tolerance in nanoseconds.

Related system properties:

  • rx3.scheduler.drift-tolerance, long, default 15
  • rx3.scheduler.drift-tolerance-unit, string, default minutes, supports seconds and milliseconds.
Returns:long

the tolerance in nanoseconds

Since
2.0
computeClockDriftback to summary
pack-priv static long computeClockDrift(long time, String timeUnit)

Returns the clock drift tolerance in nanoseconds based on the input selection.

Parameters
time:long

the time value

timeUnit:String

the time unit string

Returns:long

the time amount in nanoseconds

computeNowback to summary
pack-priv static long computeNow(TimeUnit unit)

Returns the current clock time depending on state of Scheduler#IS_DRIFT_USE_NANOTIME in given unit

By default System#currentTimeMillis() will be used as the clock. When the property is set System#nanoTime() will be used.

Parameters
unit:TimeUnit

the time unit

Returns:long

the 'current time' in given unit

Exceptions
NullPointerException:
if unit is null
createWorkerback to summary
public abstract @NonNull Scheduler.Worker createWorker()

Retrieves or creates a new Scheduler.Worker that represents sequential execution of actions.

When work is completed, the Worker instance should be released by calling Scheduler.Worker#dispose() to avoid potential resource leaks in the underlying task-execution scheme.

Work on a Scheduler.Worker is guaranteed to be sequential and non-overlapping.

Returns:@NonNull Scheduler.Worker

a Worker representing a serial queue of actions to be executed

Annotations
@NonNull
nowback to summary
public long now(@NonNull TimeUnit unit)

Returns the 'current time' of the Scheduler in the specified time unit.

Parameters
unit:@NonNull TimeUnit

the time unit

Returns:long

the 'current time'

Exceptions
NullPointerException:
if unit is null
Since
2.0
scheduleDirectback to summary
public @NonNull Disposable scheduleDirect(@NonNull Runnable run)

Schedules the given task on this Scheduler without any time delay.

This method is safe to be called from multiple threads but there are no ordering or non-overlapping guarantees between tasks.

Parameters
run:@NonNull Runnable

the task to execute

Returns:@NonNull Disposable

the Disposable instance that let's one cancel this particular task.

Annotations
@NonNull
Exceptions
NullPointerException:
if run is null
Since
2.0
scheduleDirectback to summary
public @NonNull Disposable scheduleDirect(@NonNull Runnable run, long delay, @NonNull TimeUnit unit)

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

This method is safe to be called from multiple threads but there are no ordering guarantees between tasks.

Parameters
run:@NonNull Runnable

the task to schedule

delay:long

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

unit:@NonNull TimeUnit

the unit of measure of the delay amount

Returns:@NonNull Disposable

the Disposable that let's one cancel this particular delayed task.

Annotations
@NonNull
Exceptions
NullPointerException:
if run or unit is null
Since
2.0
schedulePeriodicallyDirectback to summary
public @NonNull Disposable schedulePeriodicallyDirect(@NonNull Runnable run, long initialDelay, long period, @NonNull TimeUnit unit)

Schedules a periodic execution of the given task with the given initial time delay and repeat 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 initialDelay, the second after initialDelay + period, the third after initialDelay + 2 * period, and so on.

Parameters
run:@NonNull 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:@NonNull TimeUnit

the unit of measure of the delay amount

Returns:@NonNull Disposable

the Disposable that let's one cancel this particular delayed task.

Annotations
@NonNull
Exceptions
NullPointerException:
if run or unit is null
Since
2.0
shutdownback to summary
public void shutdown()

Instructs the Scheduler instance to stop threads, stop accepting tasks on any outstanding Worker instances and clean up any associated resources with this Scheduler.

Implementations should make sure the call is idempotent, thread-safe and should not throw any RuntimeException if it doesn't support this functionality.

Since
2.0
startback to summary
public void start()

Allows the Scheduler instance to start threads and accept tasks on them.

Implementations should make sure the call is idempotent, thread-safe and should not throw any RuntimeException if it doesn't support this functionality.

Since
2.0
whenback to summary
public <S extends Scheduler & Disposable> S when(@NonNull Function<Flowable<Flowable<Completable>>, Completable> combine)

Allows the use of operators for controlling the timing around when actions scheduled on workers are actually done. This makes it possible to layer additional behavior on this Scheduler. The only parameter is a function that flattens an Flowable of Flowable of Completables into just one Completable. There must be a chain of operators connecting the returned value to the source Flowable otherwise any work scheduled on the returned Scheduler will not be executed.

When Scheduler#createWorker() is invoked a Flowable of Completables is onNext'd to the combinator to be flattened. If the inner Flowable is not immediately subscribed to an calls to Worker#schedule are buffered. Once the Flowable is subscribed to actions are then onNext'd as Completables.

Finally the actions scheduled on the parent Scheduler when the inner most Completables are subscribed to.

When the Worker is unsubscribed the Completable emits an onComplete and triggers any behavior in the flattening operator. The Flowable and all Completables give to the flattening function never onError.

Limit the amount concurrency two at a time without creating a new fix size thread pool:

Scheduler limitScheduler = Schedulers.computation().when(workers -> {
 // use merge max concurrent to limit the number of concurrent
 // callbacks two at a time
 return Completable.merge(Flowable.merge(workers), 2);
});

This is a slightly different way to limit the concurrency but it has some interesting benefits and drawbacks to the method above. It works by limited the number of concurrent Workers rather than individual actions. Generally each Flowable uses its own Worker. This means that this will essentially limit the number of concurrent subscribes. The danger comes from using operators like Flowable#zip(org.reactivestreams.Publisher, org.reactivestreams.Publisher, io.reactivex.rxjava3.functions.BiFunction) where subscribing to the first Flowable could deadlock the subscription to the second.

Scheduler limitScheduler = Schedulers.computation().when(workers -> {
 // use merge max concurrent to limit the number of concurrent
 // Flowables two at a time
 return Completable.merge(Flowable.merge(workers, 2));
});
Slowing down the rate to no more than than 1 a second. This suffers from the same problem as the one above I could find an Flowable operator that limits the rate without dropping the values (aka leaky bucket algorithm).
Scheduler slowScheduler = Schedulers.computation().when(workers -> {
 // use concatenate to make each worker happen one at a time.
 return Completable.concat(workers.map(actions -> {
     // delay the starting of the next worker by 1 second.
     return Completable.merge(actions.delaySubscription(1, TimeUnit.SECONDS));
 }));
});

History: 2.0.1 - experimental

Parameters
<S>
a Scheduler and a Subscription
combine:@NonNull Function<Flowable<Flowable<Completable>>, Completable>

the function that takes a two-level nested Flowable sequence of a Completable and returns the Completable that will be subscribed to and should trigger the execution of the scheduled Actions.

Returns:S

the Scheduler with the customized execution behavior

Annotations
@SuppressWarnings:unchecked
@NonNull
Exceptions
NullPointerException:
if combine is null
Since
2.1
io.reactivex.rxjava3.core back to summary

pack-priv final Class Scheduler.DisposeTask

extends Object
implements Disposable, Runnable, SchedulerRunnableIntrospection
Class Inheritance
All Implemented Interfaces
io.reactivex.rxjava3.schedulers.SchedulerRunnableIntrospection, java.lang.Runnable, io.reactivex.rxjava3.disposables.Disposable

Field Summary

Modifier and TypeField and Description
pack-priv final @NonNull Runnable
pack-priv @Nullable Thread
pack-priv final @NonNull Scheduler.Worker
w

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public void
dispose()

Implements io.reactivex.rxjava3.disposables.Disposable.dispose.

Dispose the resource, the operation should be idempotent.
public Runnable
public boolean
isDisposed()

Implements io.reactivex.rxjava3.disposables.Disposable.isDisposed.

Returns true if this resource has been disposed.
public void
run()

Implements java.lang.Runnable.run.

Runs this operation.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

decoratedRunback to summary
pack-priv final @NonNull Runnable decoratedRun
Annotations
@NonNull
runnerback to summary
pack-priv @Nullable Thread runner
Annotations
@Nullable
wback to summary
pack-priv final @NonNull Scheduler.Worker w
Annotations
@NonNull

Constructor Detail

DisposeTaskback to summary
pack-priv DisposeTask(@NonNull Runnable decoratedRun, @NonNull Scheduler.Worker w)

Method Detail

disposeback to summary
public void dispose()

Implements io.reactivex.rxjava3.disposables.Disposable.dispose.

Doc from io.reactivex.rxjava3.disposables.Disposable.dispose.

Dispose the resource, the operation should be idempotent.

Annotations
@Override
getWrappedRunnableback to summary
public Runnable getWrappedRunnable()

Implements io.reactivex.rxjava3.schedulers.SchedulerRunnableIntrospection.getWrappedRunnable.

Doc from io.reactivex.rxjava3.schedulers.SchedulerRunnableIntrospection.getWrappedRunnable.

Returns the wrapped action.

Returns:Runnable

the wrapped action. Cannot be null.

Annotations
@Override
isDisposedback to summary
public boolean isDisposed()

Implements io.reactivex.rxjava3.disposables.Disposable.isDisposed.

Doc from io.reactivex.rxjava3.disposables.Disposable.isDisposed.

Returns true if this resource has been disposed.

Returns:boolean

true if this resource has been disposed

Annotations
@Override
runback to summary
public void run()

Implements java.lang.Runnable.run.

Doc from java.lang.Runnable.run.

Runs this operation.

Annotations
@Override
io.reactivex.rxjava3.core back to summary

pack-priv final Class Scheduler.PeriodicDirectTask

extends Object
implements Disposable, Runnable, SchedulerRunnableIntrospection
Class Inheritance
All Implemented Interfaces
io.reactivex.rxjava3.schedulers.SchedulerRunnableIntrospection, java.lang.Runnable, io.reactivex.rxjava3.disposables.Disposable

Field Summary

Modifier and TypeField and Description
pack-priv volatile boolean
pack-priv final @NonNull Runnable
pack-priv final @NonNull Scheduler.Worker

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public void
dispose()

Implements io.reactivex.rxjava3.disposables.Disposable.dispose.

Dispose the resource, the operation should be idempotent.
public Runnable
public boolean
isDisposed()

Implements io.reactivex.rxjava3.disposables.Disposable.isDisposed.

Returns true if this resource has been disposed.
public void
run()

Implements java.lang.Runnable.run.

Runs this operation.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

disposedback to summary
pack-priv volatile boolean disposed
runback to summary
pack-priv final @NonNull Runnable run
Annotations
@NonNull
workerback to summary
pack-priv final @NonNull Scheduler.Worker worker
Annotations
@NonNull

Constructor Detail

PeriodicDirectTaskback to summary
pack-priv PeriodicDirectTask(@NonNull Runnable run, @NonNull Scheduler.Worker worker)

Method Detail

disposeback to summary
public void dispose()

Implements io.reactivex.rxjava3.disposables.Disposable.dispose.

Doc from io.reactivex.rxjava3.disposables.Disposable.dispose.

Dispose the resource, the operation should be idempotent.

Annotations
@Override
getWrappedRunnableback to summary
public Runnable getWrappedRunnable()

Implements io.reactivex.rxjava3.schedulers.SchedulerRunnableIntrospection.getWrappedRunnable.

Doc from io.reactivex.rxjava3.schedulers.SchedulerRunnableIntrospection.getWrappedRunnable.

Returns the wrapped action.

Returns:Runnable

the wrapped action. Cannot be null.

Annotations
@Override
isDisposedback to summary
public boolean isDisposed()

Implements io.reactivex.rxjava3.disposables.Disposable.isDisposed.

Doc from io.reactivex.rxjava3.disposables.Disposable.isDisposed.

Returns true if this resource has been disposed.

Returns:boolean

true if this resource has been disposed

Annotations
@Override
runback to summary
public void run()

Implements java.lang.Runnable.run.

Doc from java.lang.Runnable.run.

Runs this operation.

Annotations
@Override
io.reactivex.rxjava3.core back to summary

public abstract Class Scheduler.Worker

extends Object
implements Disposable
Class Inheritance
All Implemented Interfaces
io.reactivex.rxjava3.disposables.Disposable
Known Direct Subclasses
io.reactivex.rxjava3.internal.schedulers.ComputationScheduler.EventLoopWorker, io.reactivex.rxjava3.internal.schedulers.ExecutorScheduler.ExecutorWorker, io.reactivex.rxjava3.internal.schedulers.ImmediateThinScheduler.ImmediateThinWorker, io.reactivex.rxjava3.internal.schedulers.IoScheduler.EventLoopWorker, io.reactivex.rxjava3.internal.schedulers.NewThreadWorker, io.reactivex.rxjava3.internal.schedulers.SchedulerWhen.QueueWorker, io.reactivex.rxjava3.internal.schedulers.SingleScheduler.ScheduledWorker, io.reactivex.rxjava3.internal.schedulers.TrampolineScheduler.TrampolineWorker, io.reactivex.rxjava3.schedulers.TestScheduler.TestWorker

Represents an isolated, sequential worker of a parent Scheduler for executing Runnable tasks on an underlying task-execution scheme (such as custom Threads, event loop, Executor or Actor system).

Disposing the Worker should cancel all outstanding work and allows resource cleanup.

The default implementations of schedule(Runnable) and schedulePeriodically(Runnable, long, long, TimeUnit) delegate to the abstract schedule(Runnable, long, TimeUnit) method. Its implementation is encouraged to track the individual Runnable tasks while they are waiting to be executed (with or without delay) so that dispose() can prevent their execution or potentially interrupt them if they are currently running.

The default implementation of the now(TimeUnit) method returns current System#currentTimeMillis() value in the desired time unit, unless rx3.scheduler.use-nanotime (boolean) is set. When the property is set to true, the method uses System#nanoTime() as its basis instead. Custom Worker implementations can override this to provide specialized time accounting (such as virtual time to be advanced programmatically). Note that operators requiring a scheduler may rely on either of the now() calls provided by Scheduler or Worker respectively, therefore, it is recommended they represent a logically consistent source of the current time.

The default implementation of the schedulePeriodically(Runnable, long, long, TimeUnit) method uses the schedule(Runnable, long, TimeUnit) for scheduling the Runnable task periodically. The algorithm calculates the next absolute time when the task should run again and schedules this execution based on the relative time between it and now(TimeUnit). However, drifts or changes in the system clock would affect this calculation either by scheduling subsequent runs too frequently or too far apart. Therefore, the default implementation uses the clockDriftTolerance() value (set via rx3.scheduler.drift-tolerance and rx3.scheduler.drift-tolerance-unit) to detect a drift in now(TimeUnit) and re-adjust the absolute/relative time calculation accordingly.

If the Worker is disposed, the schedule methods should return the Disposable#disposed() singleton instance indicating the disposed state to the caller. Since the dispose() call can happen on any thread, the schedule implementations should make best effort to cancel tasks immediately after those tasks have been submitted to the underlying task-execution scheme if the dispose was detected after this submission.

All methods on the Worker class should be thread safe.

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv class
Scheduler.Worker.PeriodicTask

Holds state and logic to calculate when the next delayed invocation of this task has to happen (accounting for clock drifts).

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public long

Returns:

the 'current time'
now
(@NonNull TimeUnit
the time unit
unit
)

Returns the 'current time' of the Worker in the specified time unit.

public @NonNull Disposable

Returns:

a Disposable to be able to unsubscribe the action (cancel it if not executed)
schedule
(@NonNull Runnable
Runnable to schedule
run
)

Schedules a Runnable for execution without any time delay.

public abstract @NonNull Disposable

Returns:

a Disposable to be able to unsubscribe the action (cancel it if not executed)
schedule
(@NonNull Runnable
the Runnable to schedule
run
,
long
time to "wait" before executing the action; non-positive values indicate an non-delayed schedule
delay
,
@NonNull TimeUnit
the time unit of delayTime
unit
)

Schedules an Runnable for execution at some point in the future specified by a time delay relative to the current time.

public @NonNull Disposable

Returns:

a Disposable to be able to unsubscribe the action (cancel it if not executed)
schedulePeriodically
(@NonNull Runnable
the Runnable to execute periodically
run
,
final long
time to wait before executing the action for the first time; non-positive values indicate an non-delayed schedule
initialDelay
,
final long
the time interval to wait each time in between executing the action; non-positive values indicate no delay between repeated schedules
period
,
final @NonNull TimeUnit
the time unit of period
unit
)

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

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

Workerback to summary
public Worker()

Method Detail

nowback to summary
public long now(@NonNull TimeUnit unit)

Returns the 'current time' of the Worker in the specified time unit.

Parameters
unit:@NonNull TimeUnit

the time unit

Returns:long

the 'current time'

Exceptions
NullPointerException:
if unit is null
Since
2.0
scheduleback to summary
public @NonNull Disposable schedule(@NonNull Runnable run)

Schedules a Runnable for execution without any time delay.

The default implementation delegates to schedule(Runnable, long, TimeUnit).

Parameters
run:@NonNull Runnable

Runnable to schedule

Returns:@NonNull Disposable

a Disposable to be able to unsubscribe the action (cancel it if not executed)

Annotations
@NonNull
Exceptions
NullPointerException:
if run is null
scheduleback to summary
public abstract @NonNull Disposable schedule(@NonNull Runnable run, long delay, @NonNull TimeUnit unit)

Schedules an Runnable for execution at some point in the future specified by a time delay relative to the current time.

Note to implementors: non-positive delayTime should be regarded as non-delayed schedule, i.e., as if the schedule(Runnable) was called.

Parameters
run:@NonNull Runnable

the Runnable to schedule

delay:long

time to "wait" before executing the action; non-positive values indicate an non-delayed schedule

unit:@NonNull TimeUnit

the time unit of delayTime

Returns:@NonNull Disposable

a Disposable to be able to unsubscribe the action (cancel it if not executed)

Annotations
@NonNull
Exceptions
NullPointerException:
if run or unit is null
schedulePeriodicallyback to summary
public @NonNull Disposable schedulePeriodically(@NonNull Runnable run, final long initialDelay, final long period, final @NonNull TimeUnit unit)

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

The default implementation schedules and reschedules the Runnable task via the schedule(Runnable, long, TimeUnit) method over and over and at a fixed rate, that is, the first execution will be after the initialDelay, the second after initialDelay + period, the third after initialDelay + 2 * period, and so on.

Note to implementors: non-positive initialTime and period should be regarded as non-delayed scheduling of the first and any subsequent executions. In addition, a more specific Worker implementation should override this method if it can perform the periodic task execution with less overhead (such as by avoiding the creation of the wrapper and tracker objects upon each periodic invocation of the common schedule(Runnable, long, TimeUnit) method).

Parameters
run:@NonNull Runnable

the Runnable to execute periodically

initialDelay:long

time to wait before executing the action for the first time; non-positive values indicate an non-delayed schedule

period:long

the time interval to wait each time in between executing the action; non-positive values indicate no delay between repeated schedules

unit:@NonNull TimeUnit

the time unit of period

Returns:@NonNull Disposable

a Disposable to be able to unsubscribe the action (cancel it if not executed)

Annotations
@NonNull
Exceptions
NullPointerException:
if run or unit is null
io.reactivex.rxjava3.core back to summary

pack-priv final Class Scheduler.Worker.PeriodicTask

extends Object
implements Runnable, SchedulerRunnableIntrospection
Class Inheritance
All Implemented Interfaces
io.reactivex.rxjava3.schedulers.SchedulerRunnableIntrospection, java.lang.Runnable

Holds state and logic to calculate when the next delayed invocation of this task has to happen (accounting for clock drifts).

Field Summary

Modifier and TypeField and Description
pack-priv long
pack-priv final @NonNull Runnable
pack-priv long
pack-priv final long
pack-priv final @NonNull SequentialDisposable
pack-priv long

Constructor Summary

AccessConstructor and Description
pack-priv
PeriodicTask(long firstStartInNanoseconds, @NonNull Runnable decoratedRun, long firstNowNanoseconds, @NonNull SequentialDisposable sd, long periodInNanoseconds)

Method Summary

Modifier and TypeMethod and Description
public Runnable
public void
run()

Implements java.lang.Runnable.run.

Runs this operation.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

countback to summary
pack-priv long count
decoratedRunback to summary
pack-priv final @NonNull Runnable decoratedRun
Annotations
@NonNull
lastNowNanosecondsback to summary
pack-priv long lastNowNanoseconds
periodInNanosecondsback to summary
pack-priv final long periodInNanoseconds
sdback to summary
pack-priv final @NonNull SequentialDisposable sd
Annotations
@NonNull
startInNanosecondsback to summary
pack-priv long startInNanoseconds

Constructor Detail

PeriodicTaskback to summary
pack-priv PeriodicTask(long firstStartInNanoseconds, @NonNull Runnable decoratedRun, long firstNowNanoseconds, @NonNull SequentialDisposable sd, long periodInNanoseconds)

Method Detail

getWrappedRunnableback to summary
public Runnable getWrappedRunnable()

Implements io.reactivex.rxjava3.schedulers.SchedulerRunnableIntrospection.getWrappedRunnable.

Doc from io.reactivex.rxjava3.schedulers.SchedulerRunnableIntrospection.getWrappedRunnable.

Returns the wrapped action.

Returns:Runnable

the wrapped action. Cannot be null.

Annotations
@Override
runback to summary
public void run()

Implements java.lang.Runnable.run.

Doc from java.lang.Runnable.run.

Runs this operation.

Annotations
@Override