delayqueue
时间: 2023-08-01 07:08:50 浏览: 109
DelayQueue
DelayQueue是一个通过PriorityBlockingQueue实现延迟获取元素的无界阻塞队列。在DelayQueue中添加的元素必须实现Delayed接口,并且只有在延迟期满后才能从队列中提取元素。\[2\]DelayQueue常用于需要延迟处理任务的场景,比如在网上商城下单后,如果超时未支付,订单会被后台系统关闭,这种需要延时处理的场景可以使用DelayQueue来实现。\[3\]DelayQueue的实现原理是基于PriorityBlockingQueue,它是一个无界阻塞队列,可以按照元素的优先级进行排序。\[2\]DelayQueue的源码定义如下:public class DelayQueue<E extends Delayed> extends AbstractQueue<E> implements BlockingQueue<E> { // ... }\[3\]
#### 引用[.reference_title]
- *1* *2* [延迟队列DelayQueue原理](https://blog.csdn.net/c15158032319/article/details/118636233)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item]
- *3* [Java 延迟队列 DelayQueue 的原理](https://blog.csdn.net/piaoranyuji/article/details/124042408)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
阅读全文