Chapter 6. Using Concurrency and Parallelism with Schedulers
Modern processors have multiple cores and enable many time-consuming operations to be processed faster simultaneously. The Java concurrency API (which includes threads and much more) makes it possible to do just that.
RxJava's Observable
chains seem a good match for the threads. It would be great if we could subscribe to our source and do all the transforming, combining, and filtering in the background and, when everything is done, have the result to be passed to the main threads. Yes, this sounds wonderful, but RxJava is single-threaded by default. This means that, in the most cases, when the subscribe
method is called on an Observable
instance, the current thread blocks until everything is emitted. (This is not true for the Observable
instances created by the interval
or timer
factory methods, for example.). This is a good thing because working with threads is not so easy. They are powerful, but they need to be...