Skip to content

Scheduler

DavidMGross edited this page Feb 6, 2014 · 38 revisions

Introduction

Content TBD

Varieties of Scheduler

You obtain a Scheduler from the factory methods described in the Schedulers class. The following table shows the varieties of Scheduler that are available to you by means of these methods:

Scheduler purpose
Schedulers.computation( ) meant for computational work such as event-loops and callback processing; do not use this scheduler for I/O (use Schedulers.io( ) instead)
Schedulers.currentThread( ) queues work to begin on the current thread after any already-queued work
Schedulers.executor( ) queues work to be done on either an Executor or ScheduledExecutorService (Note that if you use an Executor instead of a ScheduledExecutorService then the Scheduler will use a system-wide Timer to handle delayed events.)
Schedulers.immediate( ) schedules work to begin immediately in the current thread
Schedulers.io( ) meant for I/O-bound work such as asynchronous performance of blocking I/O, this scheduler is backed by an Executor thread-pool that will grow as needed; for ordinary computational work, switch to Schedulers.computation( )
Schedulers.newThread( ) creates a new thread for each unit of work
## Default Schedulers for RxJava Observable operators

Some Observable operators in RxJava have alternate forms that allow you to set which Scheduler the operator will use for (at least some part of) its operation. For these operators, if you do not set the Scheduler, the operator will use the default computation Scheduler.

Other operators do not have a form that permits you to set their Schedulers. Some of these, like startWith, empty, error, from, just, merge, and range do not use a Scheduler. A few others use particular schedulers, as in the following table:

operator Scheduler
parallelMerge currentThread
repeat currentThread
timeInterval immediate
timestamp immediate
Clone this wiki locally