문제

If I use a ThreadPoolExecutor I have a variety of constructors and I can pass/use my own queue for the pool's work queue.
Now I see that a ScheduledThreadPoolExecutor is a subclass of ThreadPoolExecutor but the constructors are much less.
Is there a way to use a ScheduledThreadPoolExecutor and still use my own work queue?

도움이 되었습니까?

해결책

You can extend ScheduledThreadPoolExecutor class and use a different queue then the DelayedWorkQueue that is bound to the current ScheduledThreadPoolExecutor implementation. Note that DelayedWorkQueue is only a BlockingQueue implementation that is using a DelayQueue behind the scene.

But if you only need to configure min, max, keepAlive or other parameters (don't need to change the DelayedWorkQueue) you will only extend ThreadPoolExecutor (similar to what ScheduledThreadPoolExecutor is doing) and in your constructor you will do something similar to what is ScheduledThreadPoolExecutor constructors is doing right now, delegate to the ThreadPoolExecutor like:

super(min, max, keepAliveTime, TimeUnit.NANOSECONDS,
   new CustomQueue(), threadFactory);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top