O'Reilly logo

Learning RxJava by Thomas Nield

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

Introducing RxJava concurrency

Concurrency in RxJava is simple to execute, but somewhat abstract to understand. By default, Observables execute work on the immediate thread, which is the thread that declared the Observer and subscribed it. In many of our earlier examples, this was the main thread that kicked off our main() method.

But as hinted in a few other examples, not all Observables will fire on the immediate thread. Remember those times we used Observable.interval(), as shown in the following code? Let's take a look:

import io.reactivex.Observable;import java.util.concurrent.TimeUnit;public class Launcher {    public static void main(String[] args) {        Observable.interval(1, TimeUnit.SECONDS)                .map(i -> i + " Mississippi")                .subscribe(

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