Reputation: 4293
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
Upvotes: 0
Views: 1110
Reputation: 116
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
Upvotes: 1
Reputation: 145
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.
Upvotes: 2