我正在使用以下代码获取我的订阅的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);
}
我使用这个调度器来让我的可观察对象在后台运行。
问题
如何为RXJava使用PriorityBlockingQueue
?通常,我会使用一些特殊的可运行对象来实现比较函数,并使用相应的比较函数替换上面示例中的LinkedBlockingQueue
,但是对于RXJava可观察对象,我该如何做呢?