简体   繁体   中英

Schedulers.computation() v/s Schedulers.io() in RxJava/RxAndroid

I have read through so many answers on SO like the following use-cases-for-rxjava-schedulers , what-is-the-difference-between-schedulers-io-and-schedulers-computation , rxjava2-schedulers-io-vs-schedulers-computation-with-large-concurrent-request .

The most common explanation is use Schedulers.computation() for CPU intensive work

and use Schedulers.io() for interaction with the file system, interaction with databases or services, REST API calls

By CPU intensive work I am assuming/considering Image Resizing/operations, Large Data sets, etc. (please add some other CPU intensive tasks if you know any which are normally performed on an Android App)

My question is

  1. what qualifies as a large data set in Android? (tangible sense)
  2. If.network calls or queries to the database respond with the huge data set(as per question 1) then what?

In fact, they just use a different thread pool and therefore need to be used for their intended purpose.

For data processing, you need to use a Schedulers.computation() , and for data input and output Schedulers.io()

This is done to limit the creation of infinitely new threads and thus to create a queue of jobs.

From the documentation of rx :

Schedulers.computation( ) - meant for computational work such as event-loops and callback processing; do not use this scheduler for I/O (use Schedulers.io( ) instead); the number of threads, by default, is equal to the number of processors

Schedulers.io( ) - meant for I/O-bound work such as asynchronous performance of blocking I/O, this scheduler is backed by a thread-pool that will grow as needed; for ordinary computational work, switch to Schedulers.computation( ); Schedulers.io( ) by default is a CachedThreadScheduler, which is something like a new thread scheduler with thread caching

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM