Class Schedulers
- java.lang.Object
-
- rx.schedulers.Schedulers
-
public final class Schedulers extends java.lang.Object
Static factory methods for creating Schedulers.
-
-
Field Summary
Fields Modifier and Type Field Description private Scheduler
computationScheduler
private static java.util.concurrent.atomic.AtomicReference<Schedulers>
INSTANCE
private Scheduler
ioScheduler
private Scheduler
newThreadScheduler
-
Constructor Summary
Constructors Modifier Constructor Description private
Schedulers()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static Scheduler
computation()
Creates and returns aScheduler
intended for computational work.static Scheduler
from(java.util.concurrent.Executor executor)
Converts anExecutor
into a new Scheduler instance.private static Schedulers
getInstance()
static Scheduler
immediate()
Creates and returns aScheduler
that executes work immediately on the current thread.static Scheduler
io()
Creates and returns aScheduler
intended for IO-bound work.static Scheduler
newThread()
Creates and returns aScheduler
that creates a newThread
for each unit of work.static void
reset()
Resets the currentSchedulers
instance.static void
shutdown()
Shuts down those standard Schedulers which support the SchedulerLifecycle interface.(package private) void
shutdownInstance()
Start the instance-specific schedulers.static void
start()
Starts those standard Schedulers which support the SchedulerLifecycle interface.(package private) void
startInstance()
Start the instance-specific schedulers.static TestScheduler
test()
Creates and returns aTestScheduler
, which is useful for debugging.static Scheduler
trampoline()
Creates and returns aScheduler
that queues work on the current thread to be executed after the current work completes.
-
-
-
Field Detail
-
computationScheduler
private final Scheduler computationScheduler
-
ioScheduler
private final Scheduler ioScheduler
-
newThreadScheduler
private final Scheduler newThreadScheduler
-
INSTANCE
private static final java.util.concurrent.atomic.AtomicReference<Schedulers> INSTANCE
-
-
Method Detail
-
getInstance
private static Schedulers getInstance()
-
immediate
public static Scheduler immediate()
Creates and returns aScheduler
that executes work immediately on the current thread.- Returns:
- a
Scheduler
that executes work immediately
-
trampoline
public static Scheduler trampoline()
Creates and returns aScheduler
that queues work on the current thread to be executed after the current work completes.- Returns:
- a
Scheduler
that queues work on the current thread
-
newThread
public static Scheduler newThread()
Creates and returns aScheduler
that creates a newThread
for each unit of work.Unhandled errors will be delivered to the scheduler Thread's
Thread.UncaughtExceptionHandler
.- Returns:
- a
Scheduler
that creates new threads
-
computation
public static Scheduler computation()
Creates and returns aScheduler
intended for computational work.This can be used for event-loops, processing callbacks and other computational work.
Do not perform IO-bound work on this scheduler. Use
io()
instead.Unhandled errors will be delivered to the scheduler Thread's
Thread.UncaughtExceptionHandler
.- Returns:
- a
Scheduler
meant for computation-bound work
-
io
public static Scheduler io()
Creates and returns aScheduler
intended for IO-bound work.The implementation is backed by an
Executor
thread-pool that will grow as needed.This can be used for asynchronously performing blocking IO.
Do not perform computational work on this scheduler. Use
computation()
instead.Unhandled errors will be delivered to the scheduler Thread's
Thread.UncaughtExceptionHandler
.- Returns:
- a
Scheduler
meant for IO-bound work
-
test
public static TestScheduler test()
Creates and returns aTestScheduler
, which is useful for debugging. It allows you to test schedules of events by manually advancing the clock at whatever pace you choose.- Returns:
- a
TestScheduler
meant for debugging
-
from
public static Scheduler from(java.util.concurrent.Executor executor)
Converts anExecutor
into a new Scheduler instance.- Parameters:
executor
- the executor to wrap- Returns:
- the new Scheduler wrapping the Executor
-
reset
@Experimental public static void reset()
Resets the currentSchedulers
instance. This will re-init the cached schedulers on the next usage, which can be useful in testing.
-
start
public static void start()
Starts those standard Schedulers which support the SchedulerLifecycle interface.The operation is idempotent and threadsafe.
-
shutdown
public static void shutdown()
Shuts down those standard Schedulers which support the SchedulerLifecycle interface.The operation is idempotent and threadsafe.
-
startInstance
void startInstance()
Start the instance-specific schedulers.
-
shutdownInstance
void shutdownInstance()
Start the instance-specific schedulers.
-
-