Schedulers basically decides the thread on which a particular code runs whether on background thread or main thread. Apart from it everything we use is from RxJava library only.
are extensively used in android programming. Below are the list of schedulers available and their brief introduction.
This is used to perform non CPU-intensive operations like making network calls, reading disc / files, database operations etc., This maintains pool of threads.
This provides access to android Main Thread / UI Thread. Usually operations like updating UI, user interactions happens on this thread. We shouldn’t perform any intensive operations on this thread as it makes the app glitchy or ANR dialog can be thrown.
Using this, a new thread will be created each time a task is scheduled. It’s usually suggested not to use schedular unless there is a very long running operation. The threads created via newThread() won’t be reused.
This schedular can be used to perform CPU-intensive operations like processing huge data, bitmap processing etc., The number of threads created using this scheduler completely depends on number CPU cores available.
This scheduler will execute all the tasks in sequential order they are added. This can be used when there is necessity of sequential execution is required.
This scheduler executes the the task immediately in synchronous way by blocking the main thread.
It executes the tasks in First In – First Out manner. All the scheduled tasks will be executed one by one by limiting the number of background threads to one.
This allows us to create a scheduler from an executor by limiting number of threads to be created. When thread pool is occupied, tasks will be queued. Now we have the basic concepts needed. Let’s start with some key concepts of RxJava that everyone should aware of.