DelayQueue
来源:互联网 发布:网络棋牌判刑 编辑:程序博客网 时间:2024/05/20 10:12
package concurrentTest;import java.util.concurrent.DelayQueue;import java.util.concurrent.Delayed;import java.util.concurrent.TimeUnit;/** * Created by mashao on 15/9/23. */public class TestDelayQueue { static class Element implements Delayed { private long trigger; private int id; public long getTrigger() { return this.trigger; } public int getId() { return this.id; } Element(long i, int id) { trigger = System.currentTimeMillis() + i; this.id = id; } public long getDelay(TimeUnit unit) { return trigger - System.currentTimeMillis(); } public int compareTo(Delayed o) { return (int)(this.getDelay(TimeUnit.MILLISECONDS) - o.getDelay(TimeUnit.MILLISECONDS)); } } public static void main(String[] args) { DelayQueue<Element> queue = new DelayQueue<Element>(); queue.add(new Element(1000L, 1)); queue.add(new Element(500L, 2)); long start = System.currentTimeMillis(); while (!queue.isEmpty()) { try { Element element = queue.take(); long period = System.currentTimeMillis() - start; System.out.println(period + ":" + element.getId()); } catch (InterruptedException e) { e.printStackTrace(); } } }}
0 0
- DelayQueue
- DelayQueue
- DelayQueue
- DelayQueue
- DelayQueue
- DelayQueue
- DelayQueue
- DelayQueue
- delayqueue
- DelayQueue
- DelayQueue 队列
- DelayQueue 用法
- DelayQueue Demo
- DelayQueue 试用
- java DelayQueue
- DelayQueue Demo
- DelayQueue 队列
- DelayQueue 队列
- 免费实用的jpg转换成pdf工具
- NoReverseMatch at /polls/2/vote/ 'polls' is not a registered namespace
- 程序员经典面试题之——数组指针与指针数组
- [Android]Native Crash at vdc
- HTTP请求的基本过程
- DelayQueue
- 递归低效以及java.lang.StackOverflowError原因
- Fragment初学1——Fragment简介
- 揭秘Apache顶级项目大数据分析引擎 Flink:与Spark的对比与分析
- Play 2.0 用户指南 - 使用JSON库 -- 针对Scala开发者
- 用Margin还是用Padding
- Spring 事务机制详解
- 基于SURF特征提取和金字塔LK光流法的单目视觉三维重建
- 神奇的图像处理算法