RxJava does not include concurrency on its own. Scheduler creates an instance of a worker that is responsible for scheduling and running code. There are 2 main operators that allow users to use scheduler ie. subscribeOn() and observeOn().

Image for post
Image for post
source

We have some builtin schedulers like Scheduler.io(), Scheduler.computation(), Scheduler.newThread() and many more, you can read them from here. In this article mainly we will try to understand observeOn and subscribeOn, also the difference between the two.

Let's start with basic code, without any observeOn or subscribeOn

without any subsribeOn or observeOn

So we see that everything runs on the same thread. By default, everything in RxJava runs on the same thread. Now let's see what happens when we use various combination of subscribeOn and observeOn. …



About

himanshu saluja

Android App Developer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store