Photo by Fancycrave on Unsplash

This blog post gathers my rules of thumb to choose the right Schedulers to observeOn() when coding with rx-java. Go through this checklist from top to bottom, until it tells you which thread is the right one to use.

Are you building an Android app and you need to change UI?

👉 AndroidSchedulers.mainThread() Are you doing IO work or other long blocking tasks? (e.g. network calls, read files):

👉 Schedulers.io() Did none of the above match?

👉 Schedulers.computation()

For unit testing, the story is a bit different. When testing your observables, you usually want your code to be executed on the same thread as the unit test to make your life simpler. Also, you want to prevent using Thread.sleep() statements whenever you use operators like timer() .

For these reasons, you should switch out your Schedulers from production code to operate on different Schedulers in your unit tests: