Why is there no default java implementation of Delayed for DelayQueue?

时光总嘲笑我的痴心妄想 提交于 2020-02-06 03:52:28

问题


I'd like a DelayQueue of scheduled Runnables, where each Runnables should only be run after a certain point in time, specified beforehand. Hence a thread can just keep removing runnables from this queue and process a schedule of events. Why is there no good default implementation of Delayed, that is also Runnable, for this?

The only subinterface of Delayed that seems reasonable is RunnableScheduledFuture, which has a whole bunch of random things that need to be implemented. There has to be an easier way to do this, right?


回答1:


DelayQueue is more of an infrastructure class that's not used directly by application.

You are probably better off using a ScheduledExecutorService (which internally uses a variant of DelayQueue)



来源:https://stackoverflow.com/questions/15102414/why-is-there-no-default-java-implementation-of-delayed-for-delayqueue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!