O'Reilly logo

Reactive Android Programming by Tadas Subonis

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Achieving parallelism

By default, code in RxJava is executed synchronously. This means that there is no concurrency and the code block is as follows:

Observable.just("One", "Two")        .doOnNext(i -> log("doOnNext", i))        .subscribe(i -> log("subscribe", i));

This will do the exact same thing as the following:

log("doOnNext", "One");log("subscribe", "One");log("doOnNext", "Two");log("subscribe", "Two");

When the code is executed on different threads, something different happens. Two pieces of code can run simultaneously, but the steps of the flow that were defined while creating Observable will always be executed in the order they were defined.

Consider the following:

Observable.just("One", "Two")        .doOnNext(i -> log("doOnNext", i)) .observeOn(Schedulers. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required