RxJava - Schedulers

RxJava - Schedulers

Schedulers are one of the main components in RxJava. They are responsible for performing operations of Observable on different threads. They help to offload the time-consuming onto different threads

Schedulers are used in multi-threading environment to work with Observable operators

By default, an Observable and the chain of operators that we apply to it will do its work, and will notify its observers, on the same thread on which its Subscribe method is called. The SubscribeOn operator changes this behavior by specifying a different Scheduler on which the Observable should operate. The ObserveOn operator specifies a different Scheduler that the Observable will use to send notifications to its observers

Below are the different types of Schedulers in RxJava

Sr.No. Scheduler & Description
1

Schedulers.computation()

Creates and returns a Scheduler intended for computational work. Count of threads to be scheduled depends upon the CPUs present in the system. One thread is allowed per CPU. Best for event-loops or callback operations.

2

Schedulers.io()

Creates and returns a Scheduler intended for IO-bound work. Thread pool may extend as needed.

3

Schedulers.newThread()

Creates and returns a Scheduler that creates a new Thread for each unit of work.

4

Schedulers.trampoline()

Creates and returns a Scheduler that queues work on the current thread to be executed after the current work completes.

5

Schedulers.from(java.util.concurrent.Executor executor)

Converts an Executor into a new Scheduler instance.

*

RxJava Tutorial RxJava - Environment Setup RxJava’s Characteristics RxJava - How Observable works RxJava - Single Observable RxJava - MayBe Observable RxJava - Completable Observable RxJava - Using CompositeDisposable RxJava - Creating Operators RxJava - Transforming Operators RxJava - Filtering Operators RxJava - Combining Operators RxJava - Utility Operators RxJava - Conditional Operators RxJava - Mathematical Operators RxJava - Subjects RxJava - PublishSubject RxJava - BehaviorSubject RxJava - AsyncSubject RxJava - ReplaySubject RxJava - Schedulers RxJava - Trampoline Scheduler RxJava - NewThread Scheduler RxJava - Computation Scheduler RxJava - IO Scheduler RxJava - From Scheduler RxJava - Buffering