-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Closed
Description
RxJava version 2.1.2.
The following code:
Single.just("Test")
.subscribeOn(Schedulers.computation())
.flatMapObservable(
s -> {
System.out.println("1: " + Thread.currentThread());
return Observable.just(1)
.observeOn(Schedulers.io())
//.doOnNext(o -> System.out.println("2: " + Thread.currentThread()))
;
}
)
.subscribe(o -> {
System.out.println("3: " + Thread.currentThread());
});...produces the following output:
1: Thread[RxComputationThreadPool-1,5,main]
3: Thread[RxComputationThreadPool-1,5,main]
Expected output here is:
1: Thread[RxComputationThreadPool-1,5,main]
3: Thread[RxCachedThreadScheduler-1,5,main]
However, when the line containing doOnNext is uncommented, this is the output:
1: Thread[RxComputationThreadPool-1,5,main]
2: Thread[RxCachedThreadScheduler-1,5,main]
3: Thread[RxCachedThreadScheduler-1,5,main]
It looks like the thread is not switched in the first case.