0

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?
Swapnil Kadam
  • 4,075
  • 5
  • 29
  • 35
  • why negative vote? – Swapnil Kadam Aug 15 '21 at 17:50
  • "what qualifies as a large data set in Android?" -- you have to ask yourself that question. You are the one who used "Large Data sets", after all. Nobody else can tell you what you think that means. "If network calls or queries to the database respond with the huge data set(as per question 1) then what?" -- if you want, switch schedulers. An RxJava chain can do some work on one scheduler, then switch schedulers. – CommonsWare Aug 18 '21 at 11:05

2 Answers2

2

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.

Ilnar
  • 146
  • 3
1

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