Java Magazine, Jan/Feb 2018
ORACLE COM JAVAMAGAZINE JANUARY FEBRUARY 2018 41 reactive programming map i i 10 map i logger info map i return i toString subscribe logger info Thread sleep 1000 You can see from the logs that all processing happens on the main thread 12 01 01097 main INFO samples RxThreading map 10 12 01 01100 main INFO samples RxThreading 10 12 01 01100 main INFO samples RxThreading map 20 12 01 01100 main INFO samples RxThreading 20 12 01 01100 main INFO samples RxThreading map 30 12 01 01100 main INFO samples RxThreading 30 12 01 01100 main INFO samples RxThreading map 40 12 01 01100 main INFO samples RxThreading 40 12 01 01100 main INFO samples RxThreading map 50 12 01 01100 main INFO samples RxThreading 50 In fact both the operator processing and the subscriber notifications happen from that main thread By default a publisher and the chain of operators that you apply to it will do its work and will notify its consumers on the same thread on which its subscribe method is called RxJava offers Schedulers to ofload work to specialized threads and executors Schedulers are responsible for notifying the subscribers on the correct thread even if its not the thread used to call subscribe The io reactivex schedulers Schedulers class offers several schedulers with the most interesting being these
You must have JavaScript enabled to view digital editions.