如果我使用一个ThreadPoolExecutor
我有各种构造函数,我可以传递/使用我自己的队列作为池的工作队列。
现在我看到一个ScheduledThreadPoolExecutor
是一个子类ThreadPoolExecutor
但构造函数要少得多。
有没有办法使用ScheduledThreadPoolExecutor
仍然使用我自己的工作队列?
你可以延长ScheduledThreadPoolExecutor
类并使用不同的队列然后DelayedWorkQueue
与当前绑定的ScheduledThreadPoolExecutor
执行。注意DelayedWorkQueue
只是一个BlockingQueue
使用的是一个实现DelayQueue
在幕后。
但如果你只需要配置min、max、keepAlive或者其他参数(不需要改变DelayedWorkQueue
)你只会延长ThreadPoolExecutor
(类似于什么ScheduledThreadPoolExecutor
正在做)并且在你的构造函数中你将做类似的事情ScheduledThreadPoolExecutor
构造函数现在正在做,委托给ThreadPoolExecutor
like:
super(min, max, keepAliveTime, TimeUnit.NANOSECONDS,
new CustomQueue(), threadFactory);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)