February 2020
Intermediate to advanced
412 pages
9h 36m
English
It is important to note that the subscribeOn() operator has no practical effect with certain sources (and keeps a worker thread unnecessarily on standby until that operation terminates). This might be because an Observable already uses a Scheduler. For example, Observable.interval() will use Schedulers.computation() and will ignore any subscribeOn() you specify, as shown here:
import io.reactivex.rxjava3.core.Observable;import io.reactivex.rxjava3.schedulers.Schedulers;public class Ch6_11 { public static void main(String[] args) { Observable.interval(1, TimeUnit.SECONDS) .subscribeOn(Schedulers.newThread()) .subscribe(i -> System.out.println("Received " + i + " on thread " + Thread.currentThread().getName())); sleep ...
Read now
Unlock full access