java DelayQueue的原理淺析
在對DelayQueue延遲功能的使用上,很多人不能后完全理解延遲的一些功能使用,這里我們深入來挖掘一下DelayQueue的原理。
下面將從構造方法、接口、繼承體系三個方面進行分析,需要注意的是,相較于其它的阻塞隊列,DelayQueue因為延遲的功能多了接口的使用,一起來看具體內(nèi)容。
1.構造方法
public DelayQueue() {}
public DelayQueue(Collection<? extends E> c) {
this.addAll(c);
}
構造方法比較簡單,一個默認構造方法,一個初始化添加集合c中所有元素的構造方法。
2.接口分析
public interface Delayed extends Comparable<Delayed> {
/**
* Returns the remaining delay associated with this object, in the
* given time unit.
*
* @param unit the time unit
* @return the remaining delay; zero or negative values indicate
* that the delay has already elapsed
*/
long getDelay(TimeUnit unit);
}
Delayed 接口有一個getDelay方法接口,該方法用來告知延遲到期有多長的時間,或者延遲在多長時間之前已經(jīng)到期,是不是很簡單。
為了排序Delayed 接口還繼承了Comparable 接口,因此必須實現(xiàn)compareTo(),使其可以進行元素的比較。
3.繼承體系

public class DelayQueue<E extends Delayed>extends AbstractQueue<E>implements BlockingQueue<E>
到此這篇關于java DelayQueue的原理淺析的文章就介紹到這了,更多相關java DelayQueue的原理內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
springboot+webmagic實現(xiàn)java爬蟲jdbc及mysql的方法
今天小編就為大家分享一篇springboot+webmagic實現(xiàn)java爬蟲jdbc及mysql的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-08-08
Java并發(fā)編程之ConcurrentLinkedQueue解讀
這篇文章主要介紹了Java并發(fā)編程之ConcurrentLinkedQueue解讀,非阻塞的實現(xiàn)方式則可以使用循環(huán)CAS的方式來實現(xiàn),而ConcurrentLinkedQueue就是juc包中自帶的經(jīng)典非堵塞方式實現(xiàn)的工具類,需要的朋友可以參考下2023-12-12

