Understanding subscribeOn()

We have touched on using subscribeOn() already, but in this section, we will explore it in more detail and look at how it works.

The subscribeOn() operator suggests to the source Observable which Scheduler to use and how to execute operations on one of its threads. If that source is not already tied to a particular Scheduler, it will use the specified Scheduler. It will then push emissions all the way to the final Observer using that thread (unless you add observeOn() calls, which we will cover later). You can put subscribeOn() anywhere in the Observable chain, and it will suggest to the source Observable which thread to execute emissions with.

In the following example, it makes no difference whether you put this ...

Get Learning RxJava - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.