Class SingleScheduler
- java.lang.Object
-
- io.reactivex.rxjava3.core.Scheduler
-
- io.reactivex.rxjava3.internal.schedulers.SingleScheduler
-
public final class SingleScheduler extends Scheduler
A scheduler with a shared, single threaded underlying ScheduledExecutorService.- Since:
- 2.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static classSingleScheduler.ScheduledWorker-
Nested classes/interfaces inherited from class io.reactivex.rxjava3.core.Scheduler
Scheduler.Worker
-
-
Field Summary
Fields Modifier and Type Field Description (package private) java.util.concurrent.atomic.AtomicReference<java.util.concurrent.ScheduledExecutorService>executorprivate static java.lang.StringKEY_SINGLE_PRIORITYThe name of the system property for setting the thread priority for this Scheduler.(package private) static java.util.concurrent.ScheduledExecutorServiceSHUTDOWN(package private) static RxThreadFactorySINGLE_THREAD_FACTORYprivate static java.lang.StringTHREAD_NAME_PREFIX(package private) java.util.concurrent.ThreadFactorythreadFactory
-
Constructor Summary
Constructors Constructor Description SingleScheduler()SingleScheduler(java.util.concurrent.ThreadFactory threadFactory)Constructs a SingleScheduler with the given ThreadFactory and prepares the single scheduler thread.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) static java.util.concurrent.ScheduledExecutorServicecreateExecutor(java.util.concurrent.ThreadFactory threadFactory)@NonNull Scheduler.WorkercreateWorker()Retrieves or creates a newScheduler.Workerthat represents sequential execution of actions.@NonNull DisposablescheduleDirect(@NonNull java.lang.Runnable run, long delay, java.util.concurrent.TimeUnit unit)Schedules the execution of the given task with the given time delay.@NonNull DisposableschedulePeriodicallyDirect(@NonNull 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 time delay and repeat period.voidshutdown()Instructs the Scheduler instance to stop threads, stop accepting tasks on any outstandingScheduler.Workerinstances and clean up any associated resources with this Scheduler.voidstart()Allows the Scheduler instance to start threads and accept tasks on them.-
Methods inherited from class io.reactivex.rxjava3.core.Scheduler
clockDriftTolerance, now, scheduleDirect, when
-
-
-
-
Field Detail
-
threadFactory
final java.util.concurrent.ThreadFactory threadFactory
-
executor
final java.util.concurrent.atomic.AtomicReference<java.util.concurrent.ScheduledExecutorService> executor
-
KEY_SINGLE_PRIORITY
private static final java.lang.String KEY_SINGLE_PRIORITY
The name of the system property for setting the thread priority for this Scheduler.- See Also:
- Constant Field Values
-
THREAD_NAME_PREFIX
private static final java.lang.String THREAD_NAME_PREFIX
- See Also:
- Constant Field Values
-
SINGLE_THREAD_FACTORY
static final RxThreadFactory SINGLE_THREAD_FACTORY
-
SHUTDOWN
static final java.util.concurrent.ScheduledExecutorService SHUTDOWN
-
-
Constructor Detail
-
SingleScheduler
public SingleScheduler()
-
SingleScheduler
public SingleScheduler(java.util.concurrent.ThreadFactory threadFactory)
Constructs a SingleScheduler with the given ThreadFactory and prepares the single scheduler thread.- Parameters:
threadFactory- thread factory to use for creating worker threads. Note that this takes precedence over any system properties for configuring new thread creation. Cannot be null.
-
-
Method Detail
-
createExecutor
static java.util.concurrent.ScheduledExecutorService createExecutor(java.util.concurrent.ThreadFactory threadFactory)
-
start
public void start()
Description copied from class:SchedulerAllows 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
RuntimeExceptionif it doesn't support this functionality.
-
shutdown
public void shutdown()
Description copied from class:SchedulerInstructs the Scheduler instance to stop threads, stop accepting tasks on any outstandingScheduler.Workerinstances and clean up any associated resources with this Scheduler.Implementations should make sure the call is idempotent, thread-safe and should not throw any
RuntimeExceptionif it doesn't support this functionality.
-
createWorker
@NonNull public @NonNull Scheduler.Worker createWorker()
Description copied from class:SchedulerRetrieves or creates a newScheduler.Workerthat represents sequential execution of actions.When work is completed, the
Workerinstance should be released by callingDisposable.dispose()to avoid potential resource leaks in the underlying task-execution scheme.Work on a
Scheduler.Workeris guaranteed to be sequential and non-overlapping.- Specified by:
createWorkerin classScheduler- Returns:
- a Worker representing a serial queue of actions to be executed
-
scheduleDirect
@NonNull public @NonNull Disposable scheduleDirect(@NonNull @NonNull java.lang.Runnable run, long delay, java.util.concurrent.TimeUnit unit)
Description copied from class:SchedulerSchedules 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.
- Overrides:
scheduleDirectin classScheduler- Parameters:
run- the task to scheduledelay- the delay amount, non-positive values indicate non-delayed schedulingunit- the unit of measure of the delay amount- Returns:
- the Disposable that let's one cancel this particular delayed task.
-
schedulePeriodicallyDirect
@NonNull public @NonNull Disposable schedulePeriodicallyDirect(@NonNull @NonNull java.lang.Runnable run, long initialDelay, long period, java.util.concurrent.TimeUnit unit)
Description copied from class:SchedulerSchedules 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 afterinitialDelay + period, the third afterinitialDelay + 2 * period, and so on.- Overrides:
schedulePeriodicallyDirectin classScheduler- Parameters:
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- Returns:
- the Disposable that let's one cancel this particular delayed task.
-
-