What is a scheduler?
In ReactiveX, the heart of concurrency lies in schedulers. As I have already mentioned, by default, the Observable and the chain of operators applied to it will do the work on the same thread where subscribe is called, and the thread will be blocked until Observer receives the onComplete
or onError
notification. We can use schedulers to change this behavior.
A scheduler can be thought of as a thread pool, from which ReactiveX can pool a thread and execute its task on it. It's basically an abstraction over multithreading and concurrency, making the implementation of concurrency a lot easier in ReactiveX.
Types of scheduler
As an abstraction layer for thread pool management, the scheduler API provides you with some pre-composed scheduler. It also allows you to create a new user-defined scheduler. Let's take a look at the available scheduler types:
Schedulers.io()
Schedulers.computation()
Schedulers.newThread()
Schedulers.single()
Schedulers.trampoline()
Schedulers.from()
We will...