Schedulers.io() on parallel database search

こ雲淡風輕ζ 提交于 2021-02-07 19:52:02

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!