I'm using following to get a ExecutorService
for my subscriptions:
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());
}
And use it like following:
public static Scheduler getBackgroundSchedular()
{
if (mBackgroundExecutorService == null)
mBackgroundExecutorService = ThreadUtil.getThreadPoolExecutorService(4);
return Schedulers.from(mBackgroundExecutorService);
}
And I use this schedular for my observables that should run in the background.
Question
How to use a PriorityBlockingQueue
for RXJava? Normally I would use some special runnables that implement a compare function and use the corresponding compare function for the PriorityBlockingQueue
and replace the LinkedBlockingQueue
in the example above with the PriorityBlockingQueue
, but how can I do this with RXJava observables?