Java Magazine, Jan/Feb 2018
ORACLE COM JAVAMAGAZINE JANUARY FEBRUARY 2018 42 reactive programming computation for CPU intensive work with no blocking I O operations io for all blocking I O operations single which is a shared thread for operations to execute in order from executor to ofload all scheduled work to a custom executor Now back to our previous example we can specify how the subscription and observation will be scheduled Flowable range 1 5 map i i 10 map i logger info map i return i toString observeOn Schedulers single subscribeOn Schedulers computation subscribe logger info Thread sleep 1000 logger info The subscribeOn method specifies the scheduling for the subscription and operator processing while the observeOn method specifies the scheduling for observing the events In this example the map operations are invoked on the computation thread pool while the subscribe callback logger info is invoked by a different thread which does not change Running the example gives an execution trace where you clearly see diferent threads being involved 12 01 03127 RxComputationThreadPool 1 INFO samples RxThreading map 10 12 01 03128 RxComputationThreadPool 1 INFO samples RxThreading map 20
You must have JavaScript enabled to view digital editions.