本文介绍了为什么没有用于DelayQueue的Delayed的默认Java实现?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要一个预定的 Runnable s,其中每个 Runnable s只能在事先指定的某个时间点之后运行。因此,线程可以继续从该队列中删除可运行对象并处理事件时间表。为什么没有,也就是 Runnable ,为此吗?

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?

Delayed 唯一合理的子接口是,其中有很多需要实施的随机事物。

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?

推荐答案

DelayQueue属于基础架构类,不能被直接使用应用程序。

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

使用ScheduledExecutorService(内部使用DelayQueue的变体)可能会更好。

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

这篇关于为什么没有用于DelayQueue的Delayed的默认Java实现?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-01 00:07