本教程操作环境:windows7系统、java10版,DELL G3电脑。
1.入队说明
因为DelayQueue是阻塞队列,且优先级队列是无界的,所以入队不会阻塞不会超时,因此它的四个入队方法是一样的。
2.入队过程
(1)加锁;
(2)添加元素到优先级队列中;
(3)如果添加的元素是堆顶元素,就把leader置为空,并唤醒等待在条件available上的线程;
(4)解锁
3.实例
(1)add
将指定的元素插入到此队列中,在成功时返回 true
publicbooleanadd(Ee){
returnoffer(e);
}
(2)offer
将指定的元素插入到此队列中,在成功时返回 true,在前面的add 中,内部调用了offer 方法,我们也可以直接调用offer 方法来完成入队操作。
/**
*Insertsthespecifiedelementintothisdelayqueue.Asthequeueis
*unboundedthismethodwillneverblock.
*
*@parametheelementtoadd
*@paramtimeoutThisparameterisignoredasthemethodneverblocks
*@paramunitThisparameterisignoredasthemethodneverblocks
*@return{@codetrue}
*@throwsNullPointerException{@inheritDoc}
*/
publicbooleanoffer(Ee,longtimeout,TimeUnitunit){
//调用offer方法
returnoffer(e);
}
原文来自:https://www.py.cn
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END


















































暂无评论内容