Introducing RxJava concurrency

Concurrency in RxJava is simple to execute, but somewhat abstract to understand. By default, an Observable executes 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.

However, as hinted in a few other examples, not every Observable fires 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.rxjava3.core.Observable;import java.time.LocalDateTime;import java.time.format.DateTimeFormatter;import java.util.concurrent.TimeUnit;public class Ch6_01 {    public static void main(String[] args) {

Get Learning RxJava - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.