DelayQueue
是实现Delayed接口的元素的一个无界阻塞队列,只有在延迟期满时才能从中提取元素。
Delayed 接口定义了 getDelay(TimeUnitunit) 方法。
该队列的头部是延迟期满后保存时间最长的Delayed元素。如果延迟都还没有期满,则队列没有头部,
并且poll将返回null。当一个元素的 getDelay(TimeUnitunit) 方法返回一个小于或等于零的值时,则出现期满。
<wbr style="line-height:22px">注意1</wbr><wbr style="line-height:22px">:它是无界阻塞队列,容量是无限的。<br style="line-height:22px"><span style="line-height:22px"><wbr style="line-height:22px">注意2</wbr></span><wbr style="line-height:22px">:它是线程安全的,是阻塞的<br style="line-height:22px"><span style="line-height:22px"><wbr style="line-height:22px">注意3</wbr></span><wbr style="line-height:22px">:不允许使用null元素。<br style="line-height:22px"><span style="line-height:22px"><wbr style="line-height:22px">注意4</wbr></span><wbr style="line-height:22px">:加入的元素必须实现了Delayed接口。<br style="line-height:22px"><span style="color:#0000ff; line-height:25px">publicinterfaceDelayed<br style="line-height:22px"> extendsComparable<Delayed></span><br style="line-height:22px"> Delayed是一种混合风格的接口,用来标记那些应该在给定延迟时间之后执行的对象。<br style="line-height:22px"> 此接口的实现必须定义一个compareTo方法,该方法提供与此接口的getDelay方法一致的排序。<br style="line-height:22px"><span style="line-height:22px"><wbr style="line-height:22px">注意5</wbr></span><wbr style="line-height:22px">:对于put(Eo)和offer(Eo,longtimeout,TimeUnitunit),由于该队列是无界的,所以此方法永远不会阻塞。<br style="line-height:22px"> 因此参数timeout和unit没意义,会被忽略掉。<br style="line-height:22px"><span style="line-height:22px"><wbr style="line-height:22px">注意6</wbr></span>:此类及其迭代器实现了Collection和Iterator接口的所有可选方法。<wbr style="line-height:25px"><div style="line-height:25px"> <span style="line-height:22px"><span style="line-height:22px">实例1</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">importjava.util.Random;</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">importjava.util.concurrent.BlockingQueue;</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">importjava.util.concurrent.DelayQueue;</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">importjava.util.concurrent.Delayed;</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">importjava.util.concurrent.TimeUnit;</span><br style="line-height:22px"><span style="color:#993300; line-height:25px">publicclass</span><span style="color:#3366ff; line-height:25px">Test{</span><br style="line-height:22px"><span style="color:#808080; line-height:25px">/**<br style="line-height:22px"> *@paramargs<br style="line-height:22px"> */</span><br style="line-height:22px"><span style="color:#993300; line-height:25px">publicstaticvoid</span><span style="color:#3366ff; line-height:25px">main(String[]args){</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">BlockingQueue<Task>queue=newDelayQueue();</span><br style="line-height:22px"><span style="color:#808080; line-height:25px">//TODOAuto-generatedmethodstub</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px"></span><span style="color:#993300; line-height:25px">for</span><span style="color:#3366ff; line-height:25px">(inti=0;i<10;i++)</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">newThread(newThreadProducer(queue)).start();</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px"></span><span style="color:#993300; line-height:25px">for</span><span style="color:#3366ff; line-height:25px">(inti=0;i<10;i++)</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">newThread(newThreadConsumer(queue)).start();</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">}</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">}</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">classTaskimplementsDelayed</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">{</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">Stringname;</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">longsubmitTime;</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">Task(StringtaskName,long</span><span style="color:#99cc00; line-height:25px">delayTime</span><span style="color:#3366ff; line-height:25px">)</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">{</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">name=taskName;</span><br style="line-height:22px"><span style="color:#808080; line-height:25px">/*converthetimefromMILLISECONDStoNANOSECONDS<br style="line-height:22px"> **<br style="line-height:22px"> */</span><br style="line-height:22px"><span style="color:#0000ff; line-height:25px">submitTime=TimeUnit.NANOSECONDS.convert(</span><span style="color:#99cc00; line-height:25px">delayTime</span><span style="color:#0000ff; line-height:25px">,TimeUnit.MILLISECONDS)+System.nanoTime();</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">}</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px"></span><span style="color:#993300; line-height:25px">publiclong</span><span style="color:#3366ff; line-height:25px">getDelay(TimeUnitunit)</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">{</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px"> System.out.println("getdelay");</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">returnunit.convert(submitTime-System.nanoTime(),TimeUnit.NANOSECONDS);</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">}</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px"></span><span style="color:#993300; line-height:25px">publicint</span><span style="color:#3366ff; line-height:25px">compareTo(Delayedo)</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">{</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">System.out.println("compareTo");</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">Taskthat=(Task)o;</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">returnsubmitTime>that.submitTime?1:(submitTime<that.submitTime?-1:0);</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">}</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px"></span><span style="color:#993300; line-height:25px">void</span><span style="color:#3366ff; line-height:25px">doTask()</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">{</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">System.out.println("dotask:"+name);</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">}</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">}</span><br style="line-height:22px"><span style="color:#993300; line-height:25px">class</span><span style="color:#3366ff; line-height:25px">ThreadProducerimplementsRunnable</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">{</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">ThreadProducer(BlockingQueue<Task>queue)</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">{</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">this.queue=queue;</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">}</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">BlockingQueue<Task>queue;</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">staticintcnt=0;</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px"></span><span style="color:#993300; line-height:25px">publicvoid</span><span style="color:#3366ff; line-height:25px">run()</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">{</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">Tasktask;</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">Randomrandom=newRandom(System.currentTimeMillis());</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">while(true)</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">{</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">task=newTask(""+(cnt),random.nextInt()&0xFFFF);</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">cnt=(cnt+1)&0xFFFFFFFF;</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">try{</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">queue.put(task);</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">Thread.sleep(1);</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">}catch(InterruptedExceptione)</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">{</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">e.printStackTrace();</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">}</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">}</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">}</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">}</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">classThreadConsumerimplementsRunnable</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">{</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">ThreadConsumer(BlockingQueue<Task>queue)</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">{</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">this.queue=queue;</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">}</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">BlockingQueue<Task>queue;</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">publicvoidrun()</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">{</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">Tasktask;</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">while(true)</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">{</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">try{</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">task=queue.take();</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">task.doTask();</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">Thread.sleep(1);</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">}catch(InterruptedExceptione)</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">{</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">e.printStackTrace();</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">}</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">}</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">}</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">}</span><br style="line-height:22px"><span style="line-height:22px"><wbr style="line-height:22px"><span style="line-height:25px">注意1:</span>关于TimeUnit的知识请参照</wbr></span>《<span style="line-height:24px; font-family:Arial,Helvetica,simsun,u5b8bu4f53; white-space:nowrap"><a title="阅读全文" target="_blank" href="http://hubingforever.blog.163.com/blog/static/17104057920107323852915/" style="color:rgb(207,121,28); line-height:22px; text-decoration:underline">TimeUnit</a></span></span><span style="line-height:22px">》<br style="line-height:22px"><span style="line-height:22px">注意2:</span><span style="line-height:22px">compareTo(Delayedo)这里是用于对元素排序的。</span></span> </div> </wbr></wbr></wbr></wbr></wbr></wbr>
Delayed 接口定义了 getDelay(TimeUnitunit) 方法。
该队列的头部是延迟期满后保存时间最长的Delayed元素。如果延迟都还没有期满,则队列没有头部,
并且poll将返回null。当一个元素的 getDelay(TimeUnitunit) 方法返回一个小于或等于零的值时,则出现期满。
<wbr style="line-height:22px">注意1</wbr><wbr style="line-height:22px">:它是无界阻塞队列,容量是无限的。<br style="line-height:22px"><span style="line-height:22px"><wbr style="line-height:22px">注意2</wbr></span><wbr style="line-height:22px">:它是线程安全的,是阻塞的<br style="line-height:22px"><span style="line-height:22px"><wbr style="line-height:22px">注意3</wbr></span><wbr style="line-height:22px">:不允许使用null元素。<br style="line-height:22px"><span style="line-height:22px"><wbr style="line-height:22px">注意4</wbr></span><wbr style="line-height:22px">:加入的元素必须实现了Delayed接口。<br style="line-height:22px"><span style="color:#0000ff; line-height:25px">publicinterfaceDelayed<br style="line-height:22px"> extendsComparable<Delayed></span><br style="line-height:22px"> Delayed是一种混合风格的接口,用来标记那些应该在给定延迟时间之后执行的对象。<br style="line-height:22px"> 此接口的实现必须定义一个compareTo方法,该方法提供与此接口的getDelay方法一致的排序。<br style="line-height:22px"><span style="line-height:22px"><wbr style="line-height:22px">注意5</wbr></span><wbr style="line-height:22px">:对于put(Eo)和offer(Eo,longtimeout,TimeUnitunit),由于该队列是无界的,所以此方法永远不会阻塞。<br style="line-height:22px"> 因此参数timeout和unit没意义,会被忽略掉。<br style="line-height:22px"><span style="line-height:22px"><wbr style="line-height:22px">注意6</wbr></span>:此类及其迭代器实现了Collection和Iterator接口的所有可选方法。<wbr style="line-height:25px"><div style="line-height:25px"> <span style="line-height:22px"><span style="line-height:22px">实例1</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">importjava.util.Random;</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">importjava.util.concurrent.BlockingQueue;</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">importjava.util.concurrent.DelayQueue;</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">importjava.util.concurrent.Delayed;</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">importjava.util.concurrent.TimeUnit;</span><br style="line-height:22px"><span style="color:#993300; line-height:25px">publicclass</span><span style="color:#3366ff; line-height:25px">Test{</span><br style="line-height:22px"><span style="color:#808080; line-height:25px">/**<br style="line-height:22px"> *@paramargs<br style="line-height:22px"> */</span><br style="line-height:22px"><span style="color:#993300; line-height:25px">publicstaticvoid</span><span style="color:#3366ff; line-height:25px">main(String[]args){</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">BlockingQueue<Task>queue=newDelayQueue();</span><br style="line-height:22px"><span style="color:#808080; line-height:25px">//TODOAuto-generatedmethodstub</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px"></span><span style="color:#993300; line-height:25px">for</span><span style="color:#3366ff; line-height:25px">(inti=0;i<10;i++)</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">newThread(newThreadProducer(queue)).start();</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px"></span><span style="color:#993300; line-height:25px">for</span><span style="color:#3366ff; line-height:25px">(inti=0;i<10;i++)</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">newThread(newThreadConsumer(queue)).start();</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">}</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">}</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">classTaskimplementsDelayed</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">{</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">Stringname;</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">longsubmitTime;</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">Task(StringtaskName,long</span><span style="color:#99cc00; line-height:25px">delayTime</span><span style="color:#3366ff; line-height:25px">)</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">{</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">name=taskName;</span><br style="line-height:22px"><span style="color:#808080; line-height:25px">/*converthetimefromMILLISECONDStoNANOSECONDS<br style="line-height:22px"> **<br style="line-height:22px"> */</span><br style="line-height:22px"><span style="color:#0000ff; line-height:25px">submitTime=TimeUnit.NANOSECONDS.convert(</span><span style="color:#99cc00; line-height:25px">delayTime</span><span style="color:#0000ff; line-height:25px">,TimeUnit.MILLISECONDS)+System.nanoTime();</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">}</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px"></span><span style="color:#993300; line-height:25px">publiclong</span><span style="color:#3366ff; line-height:25px">getDelay(TimeUnitunit)</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">{</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px"> System.out.println("getdelay");</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">returnunit.convert(submitTime-System.nanoTime(),TimeUnit.NANOSECONDS);</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">}</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px"></span><span style="color:#993300; line-height:25px">publicint</span><span style="color:#3366ff; line-height:25px">compareTo(Delayedo)</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">{</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">System.out.println("compareTo");</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">Taskthat=(Task)o;</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">returnsubmitTime>that.submitTime?1:(submitTime<that.submitTime?-1:0);</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">}</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px"></span><span style="color:#993300; line-height:25px">void</span><span style="color:#3366ff; line-height:25px">doTask()</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">{</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">System.out.println("dotask:"+name);</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">}</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">}</span><br style="line-height:22px"><span style="color:#993300; line-height:25px">class</span><span style="color:#3366ff; line-height:25px">ThreadProducerimplementsRunnable</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">{</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">ThreadProducer(BlockingQueue<Task>queue)</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">{</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">this.queue=queue;</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">}</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">BlockingQueue<Task>queue;</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">staticintcnt=0;</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px"></span><span style="color:#993300; line-height:25px">publicvoid</span><span style="color:#3366ff; line-height:25px">run()</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">{</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">Tasktask;</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">Randomrandom=newRandom(System.currentTimeMillis());</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">while(true)</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">{</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">task=newTask(""+(cnt),random.nextInt()&0xFFFF);</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">cnt=(cnt+1)&0xFFFFFFFF;</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">try{</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">queue.put(task);</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">Thread.sleep(1);</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">}catch(InterruptedExceptione)</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">{</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">e.printStackTrace();</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">}</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">}</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">}</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">}</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">classThreadConsumerimplementsRunnable</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">{</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">ThreadConsumer(BlockingQueue<Task>queue)</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">{</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">this.queue=queue;</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">}</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">BlockingQueue<Task>queue;</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">publicvoidrun()</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">{</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">Tasktask;</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">while(true)</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">{</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">try{</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">task=queue.take();</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">task.doTask();</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">Thread.sleep(1);</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">}catch(InterruptedExceptione)</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">{</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">e.printStackTrace();</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">}</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">}</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">}</span><br style="line-height:22px"><span style="color:#3366ff; line-height:25px">}</span><br style="line-height:22px"><span style="line-height:22px"><wbr style="line-height:22px"><span style="line-height:25px">注意1:</span>关于TimeUnit的知识请参照</wbr></span>《<span style="line-height:24px; font-family:Arial,Helvetica,simsun,u5b8bu4f53; white-space:nowrap"><a title="阅读全文" target="_blank" href="http://hubingforever.blog.163.com/blog/static/17104057920107323852915/" style="color:rgb(207,121,28); line-height:22px; text-decoration:underline">TimeUnit</a></span></span><span style="line-height:22px">》<br style="line-height:22px"><span style="line-height:22px">注意2:</span><span style="line-height:22px">compareTo(Delayedo)这里是用于对元素排序的。</span></span> </div> </wbr></wbr></wbr></wbr></wbr></wbr>