java DelayQueue的原理淺析
在對(duì)DelayQueue延遲功能的使用上,很多人不能后完全理解延遲的一些功能使用,這里我們深入來(lái)挖掘一下DelayQueue的原理。
下面將從構(gòu)造方法、接口、繼承體系三個(gè)方面進(jìn)行分析,需要注意的是,相較于其它的阻塞隊(duì)列,DelayQueue因?yàn)檠舆t的功能多了接口的使用,一起來(lái)看具體內(nèi)容。
1.構(gòu)造方法public DelayQueue() {}public DelayQueue(Collection<? extends E> c) { this.addAll(c);}
構(gòu)造方法比較簡(jiǎn)單,一個(gè)默認(rèn)構(gòu)造方法,一個(gè)初始化添加集合c中所有元素的構(gòu)造方法。
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 接口有一個(gè)getDelay方法接口,該方法用來(lái)告知延遲到期有多長(zhǎng)的時(shí)間,或者延遲在多長(zhǎng)時(shí)間之前已經(jīng)到期,是不是很簡(jiǎn)單。
為了排序Delayed 接口還繼承了Comparable 接口,因此必須實(shí)現(xiàn)compareTo(),使其可以進(jìn)行元素的比較。
3.繼承體系public class DelayQueue<E extends Delayed>extends AbstractQueue<E>implements BlockingQueue<E>
到此這篇關(guān)于java DelayQueue的原理淺析的文章就介紹到這了,更多相關(guān)java DelayQueue的原理內(nèi)容請(qǐng)搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!
相關(guān)文章:
1. Ajax實(shí)現(xiàn)表格中信息不刷新頁(yè)面進(jìn)行更新數(shù)據(jù)2. 詳解CSS偽元素的妙用單標(biāo)簽之美3. pip已經(jīng)安裝好第三方庫(kù)但pycharm中import時(shí)還是標(biāo)紅的解決方案4. 使用Python FastAPI構(gòu)建Web服務(wù)的實(shí)現(xiàn)5. UDDI FAQs6. msxml3.dll 錯(cuò)誤 800c0019 系統(tǒng)錯(cuò)誤:-2146697191解決方法7. HTML <!DOCTYPE> 標(biāo)簽8. Python collections模塊的使用方法9. CSS自定義滾動(dòng)條樣式案例詳解10. 將properties文件的配置設(shè)置為整個(gè)Web應(yīng)用的全局變量實(shí)現(xiàn)方法
