Search⌘ K
AI Features

Achieving True Concurrency

Explore how to achieve true concurrency in RxJava by leveraging the flatMap operator along with Schedulers. Understand the limitations of subscribeOn and observeOn, and learn to execute concurrent network requests on separate threads for improved reactive app performance.

So far, we have looked at ways to introduce multithreading through the use of Schedulers along with the .subscribeOn() and .observeOn() operators. To achieve true concurrency, however, these operators alone are not sufficient.

The basics of true concurrency

If you noticed in our example of using .subscribeOn(), events received from upstream are not processed on separate threads. All emissions were executed on the same thread, RxCachedThreadScheduler-1. To achieve true concurrency, we need the help of .flatMap().

...