One last concurrency operator that we need to cover is unsubscribeOn(). Disposing of an Observable can be an expensive (in terms of the time it takes) operation, depending on the nature of the source. For instance, if the Observable emits the results of a database query using RxJava-JDBC, (https://github.com/davidmoten/rxjava-jdbc), it can be expensive to dispose of because it needs to shut down the JDBC resources it is using. This can cause the thread that calls dispose() to become busy. If this is a UI thread in JavaFX or Android (for instance, because a CANCEL PROCESSING button was clicked), this can cause undesirable UI freezing.
Here is a simple Observable that is emitting every second. We stop the main thread for 3 seconds and then call dispose() to shut the operation down. Let's use doOnDispose() (which will be executed by the disposing...