Class NewThreadWorker
java.lang.Object
io.reactivex.rxjava3.core.Scheduler.Worker
io.reactivex.rxjava3.internal.schedulers.NewThreadWorker
- All Implemented Interfaces:
Disposable
- Direct Known Subclasses:
ComputationScheduler.PoolWorker, IoScheduler.ThreadWorker
Base class that manages a single-threaded ScheduledExecutorService as a
worker but doesn't perform task-tracking operations.
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) booleanprivate final ScheduledExecutorService -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoiddispose()Dispose the resource, the operation should be idempotent.booleanReturns true if this resource has been disposed.Schedules a Runnable for execution without any time delay.Schedules an Runnable for execution at some point in the future specified by a time delay relative to the current time.scheduleActual(Runnable run, long delayTime, @NonNull TimeUnit unit, @Nullable DisposableContainer parent) Wraps and returns the given runnable into a ScheduledRunnable and schedules it on the underlying ScheduledExecutorService.scheduleDirect(Runnable run, long delayTime, TimeUnit unit) Schedules the given runnable on the underlying executor directly and returns its future wrapped into a Disposable.schedulePeriodicallyDirect(Runnable run, long initialDelay, long period, TimeUnit unit) Schedules the given runnable periodically on the underlying executor directly and returns its future wrapped into a Disposable.voidshutdown()Shuts down the underlying executor in a non-interrupting fashion.Methods inherited from class Scheduler.Worker
now, schedulePeriodically
-
Field Details
-
executor
-
disposed
volatile boolean disposed
-
-
Constructor Details
-
NewThreadWorker
-
-
Method Details
-
schedule
Description copied from class:Scheduler.WorkerSchedules a Runnable for execution without any time delay.The default implementation delegates to
Scheduler.Worker.schedule(Runnable, long, TimeUnit).- Overrides:
schedulein classScheduler.Worker- Parameters:
run- Runnable to schedule- Returns:
- a Disposable to be able to unsubscribe the action (cancel it if not executed)
-
schedule
@NonNull public @NonNull Disposable schedule(@NonNull @NonNull Runnable action, long delayTime, @NonNull @NonNull TimeUnit unit) Description copied from class:Scheduler.WorkerSchedules 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
delayTimeshould be regarded as non-delayed schedule, i.e., as if theScheduler.Worker.schedule(Runnable)was called.- Specified by:
schedulein classScheduler.Worker- Parameters:
action- the Runnable to scheduledelayTime- time to "wait" before executing the action; non-positive values indicate an non-delayed scheduleunit- the time unit ofdelayTime- Returns:
- a Disposable to be able to unsubscribe the action (cancel it if not executed)
-
scheduleDirect
Schedules the given runnable on the underlying executor directly and returns its future wrapped into a Disposable.- Parameters:
run- the Runnable to execute in a delayed fashiondelayTime- the delay amountunit- the delay time unit- Returns:
- the ScheduledRunnable instance
-
schedulePeriodicallyDirect
public Disposable schedulePeriodicallyDirect(Runnable run, long initialDelay, long period, TimeUnit unit) Schedules the given runnable periodically on the underlying executor directly and returns its future wrapped into a Disposable.- Parameters:
run- the Runnable to execute in a periodic fashioninitialDelay- the initial delay amountperiod- the repeat period amountunit- the time unit for both the initialDelay and period- Returns:
- the ScheduledRunnable instance
-
scheduleActual
@NonNull public @NonNull ScheduledRunnable scheduleActual(Runnable run, long delayTime, @NonNull @NonNull TimeUnit unit, @Nullable @Nullable DisposableContainer parent) Wraps and returns the given runnable into a ScheduledRunnable and schedules it on the underlying ScheduledExecutorService.- Parameters:
run- the runnable instancedelayTime- the time to delay the executionunit- the time unitparent- the optional tracker parent to add the created ScheduledRunnable instance to before it gets scheduled- Returns:
- the ScheduledRunnable instance
-
dispose
public void dispose()Description copied from interface:DisposableDispose the resource, the operation should be idempotent. -
shutdown
public void shutdown()Shuts down the underlying executor in a non-interrupting fashion. -
isDisposed
public boolean isDisposed()Description copied from interface:DisposableReturns true if this resource has been disposed.- Returns:
- true if this resource has been disposed
-