Asynchronous RestAPIs with RxJava/Jersey2. Threading questions?

余生颓废 提交于 2019-12-03 09:08:00

1) In RxJava itself, if an method requires a scheduler, we create two overloads: one without a Scheduler parameter and one with it. The former then delegates to the latter with a reasonable default scheduler. This way, API consumers may chose to accept the default or go with their own.

2) It depends on your computation. If the computation takes similar time as to wait for the IO, you could move the computation into the computation scheduler, thus freeing up the cached worker threads inside IO to do more blocking. Otherwise, you could just do the business logic on the same scheduler.

3) You can't configure the pool sizes in RxJava at the moment. Computation will always use Runtime.availableProcessors() and IO will be always act as an unbounded cached threadpool. If you can live with events thread-hopping (meaning: they are guaranteed to be serial but one event may execute on thread 1 and the subsequent on thread 2), you can use your own ExecutorServices via Schedulers.from().

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