问题
I wonder whether I should use Schedulers.io() or Schedulers.newThread() when I access to database tables in parallel.
For example, if I use Schedulers.io() to select the records from thousands of tables in parallel, a lot of threads newly created were in the thread pool after the task.
Observabe.just("table1", "table2", "table3"...)
.flatMap(t -> {
// creating the observable that emits the record
return Observable create(s -> {
Record rec = selectFrom(t);
s.onNext(rec);
s.onCompleted();
})
.subscribeOn(Schedulers.io()); // select in parallel
})...
However, if such task were a nightly batch, those threads do not have to be in the thread pool since most of them were not needed in most of the time.
In this case, I think that I should use Schedulers.newThread(). Is it right?
回答1:
If you want to limit io work in parallel then use a custom Scheduler
:
Scheduler scheduler = Schedulers.from(Executors.newFixedThreadPool(6));
来源:https://stackoverflow.com/questions/38284285/schedulers-io-on-parallel-database-search