DelayQueue
来源:互联网 发布:淘宝双11秒杀技巧 编辑:程序博客网 时间:2024/05/30 21:58
DelayQueue
class implements the BlockingQueue
interface. Read the BlockingQueue
text for more information about the interface.The DelayQueue
blocks the elements internally until a certain delay has expired. The elements must implement the interface java.util.concurrent.Delayed
. Here is how the interface looks:
public interface Delayed extends Comparable<Delayed< { public long getDelay(TimeUnit timeUnit);}
The value returned by the getDelay()
method should be the delay remaining before this element can be released. If 0 or a negative value is returned, the delay will be considered expired, and the element released at the next take()
etc. call on the DelayQueue
.
The TimeUnit
instance passed to the getDelay()
method is an Enum
that tells which time unit the delay should be returned in. The TimeUnit
enum can take these values:
DAYSHOURSMINUTESSECONDSMILLISECONDSMICROSECONDSNANOSECONDS
The Delayed
interface also extends the java.lang.Comparable
interface, as you can see, which means thatDelayed
objects can be compared to each other. This is probably used internally in the DelayQueue
to order the elements in the queue, so they are released ordered by their expiration time.
Here is an example of how to use the DelayQueue
:
public class DelayQueueExample { public static void main(String[] args) { DelayQueue queue = new DelayQueue(); Delayed element1 = new DelayedElement(); queue.put(element1); Delayed element2 = queue.take(); }}
The DelayedElement
is an implementation of the Delayed
interface that I have created. It is not part of thejava.util.concurrent
package. You will have to create your own implementation of the Delayed
interface to use the DelayQueue
class.
- DelayQueue
- DelayQueue
- DelayQueue
- DelayQueue
- DelayQueue
- DelayQueue
- DelayQueue
- DelayQueue
- delayqueue
- DelayQueue
- DelayQueue 队列
- DelayQueue 用法
- DelayQueue Demo
- DelayQueue 试用
- java DelayQueue
- DelayQueue Demo
- DelayQueue 队列
- DelayQueue 队列
- Redshift 性能测试(一)
- AngularJS之表格序号
- 在使用AWS时遇到的问题
- ArrayBlockingQueue
- 单片机控制继电器 使LED灯交替闪烁
- DelayQueue
- servlet几种跳转方法的路径怎么写
- hive中启动metastore
- 微信开发--如何存储并定时更新access_token
- LinkedBlockingQueue
- String中的常用方法
- 二分查找 C 、C++STL
- PriorityBlockingQueue
- HBase的Block Cache实现机制分析