According to this question, Schedulers.io()
will create an unbounded number of threads. In my application, this is an issue because I have hundreds of asynchonous tasks to complete.
The recommendation in the comments is to use Scheduler.from(Executors.newFixedThreadPool(n))
, which is reasonable, but the usage pattern is different to Schedulers.io()
:
- With
Schedulers.io()
, I can re-use the same thread-pool through-out my application, and Rx will properly callshutdown
for me. - With
Scheduler.from(Executors.newFixedThreadPool(n))
, I have to make theScheduler
available across my application and remember to callshutdown
.
Questions:
- Can I just tweak the behaviour of
Schedulers.io()
to use a bounded thread-pool? - What is the recommended way to thread a
Scheduler
through-out an Rx application, and ensure that it isshutdown
correctly?