RxJava subscribeOn and observeOn

The SubscribeOn operator changes this behavior by specifying a different Scheduler on which the Observable should operate.

The ObserveOn operator specifies a different Scheduler that the Observable will use to send notifications to its observers.

The SubscribeOn operator designates which thread the Observable will begin operating on, no matter at what point in the chain of operators that operator is called. 

ObserveOn, on the other hand, affects the thread that the Observable will use below where that operator appears.

 

ObserveOn影响其后操作使用的线程

SubscribeOn影响所有操作, 但ObserveOn优先

SubscribeOn在chain中的位置无所谓

多个SubscribeOn,第一个有效

 

 

测试代码:

 

 

参考http://reactivex.io/documentation/scheduler.html

http://www.grahamlea.com/2014/07/rxjava-threading-examples/

猜你喜欢

转载自simplehappy.iteye.com/blog/2294250