【发布时间】:2016-06-03 21:12:09
【问题描述】:
我正在使用以下内容为我的订阅获取ExecutorService:
public static ExecutorService getThreadPoolExecutorService(int threads)
{
int NUMBER_OF_CORES = Runtime.getRuntime().availableProcessors();
ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(
NUMBER_OF_CORES * 2,
NUMBER_OF_CORES * 2,
60L,
TimeUnit.SECONDS,
new LinkedBlockingQueue<Runnable>()
);
return Executors.newFixedThreadPool(threads, threadPoolExecutor.getThreadFactory());
}
并像下面这样使用它:
public static Scheduler getBackgroundSchedular()
{
if (mBackgroundExecutorService == null)
mBackgroundExecutorService = ThreadUtil.getThreadPoolExecutorService(4);
return Schedulers.from(mBackgroundExecutorService);
}
我将这个时间表用于应该在后台运行的 observables。
问题
如何为 RXJava 使用PriorityBlockingQueue?通常我会使用一些特殊的runnables来实现比较函数,并为PriorityBlockingQueue使用相应的比较函数,并将上面示例中的LinkedBlockingQueue替换为PriorityBlockingQueue,但是如何使用RXJava observables做到这一点?
【问题讨论】:
标签: android multithreading threadpool rx-java