Package rx.internal.schedulers
Class GenericScheduledExecutorService
- java.lang.Object
-
- rx.internal.schedulers.GenericScheduledExecutorService
-
- All Implemented Interfaces:
SchedulerLifecycle
public final class GenericScheduledExecutorService extends java.lang.Object implements SchedulerLifecycle
A defaultScheduledExecutorService
that can be used for scheduling actions when aScheduler
implementation doesn't have that ability.For example if a
Scheduler
is given anExecutor
or {ExecutorService
instead ofScheduledExecutorService
.NOTE: No actual work should be done on tasks submitted to this executor. Submit a task with the appropriate delay which then in turn invokes the work asynchronously on the appropriate
Scheduler
implementation. This means for example that you would not use this approach along withTrampolineScheduler
orImmediateScheduler
.
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.concurrent.atomic.AtomicReference<java.util.concurrent.ScheduledExecutorService[]>
executor
static GenericScheduledExecutorService
INSTANCE
private static java.util.concurrent.ScheduledExecutorService[]
NONE
private static int
roundRobin
We don't use atomics with this because thread-assignment is random anyway.private static java.util.concurrent.ScheduledExecutorService
SHUTDOWN
-
Constructor Summary
Constructors Modifier Constructor Description private
GenericScheduledExecutorService()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static java.util.concurrent.ScheduledExecutorService
getInstance()
Returns one of the single-threaded ScheduledExecutorService helper executors.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.
-
-
-
Field Detail
-
NONE
private static final java.util.concurrent.ScheduledExecutorService[] NONE
-
SHUTDOWN
private static final java.util.concurrent.ScheduledExecutorService SHUTDOWN
-
INSTANCE
public static final GenericScheduledExecutorService INSTANCE
-
executor
private final java.util.concurrent.atomic.AtomicReference<java.util.concurrent.ScheduledExecutorService[]> executor
-
roundRobin
private static int roundRobin
We don't use atomics with this because thread-assignment is random anyway.
-
-
Method Detail
-
start
public void start()
Description copied from interface:SchedulerLifecycle
Allows the Scheduler instance to start threads and accept tasks on them.Implementations should make sure the call is idempotent and threadsafe.
- Specified by:
start
in interfaceSchedulerLifecycle
-
shutdown
public void shutdown()
Description copied from interface:SchedulerLifecycle
Instructs the Scheduler instance to stop threads and stop accepting tasks on any outstanding Workers.Implementations should make sure the call is idempotent and threadsafe.
- Specified by:
shutdown
in interfaceSchedulerLifecycle
-
getInstance
public static java.util.concurrent.ScheduledExecutorService getInstance()
Returns one of the single-threaded ScheduledExecutorService helper executors.- Returns:
ScheduledExecutorService
for generic use.
-
-