> ### `LinkedBlockingQueue`
* `FixedThreadPool`和`SingleThreadExecutor`中的阻塞隊列
<br/>
> ### `SynchronousQueue`
* `CachedThreadPool`中的阻塞隊列
<br/>
> ### `DelayQueue`
* `ScheduledThreadPoolExecutor`中的阻塞隊列
* 使用實例,元素需要繼承`Delayed`接口
```
public class DelayQueueTest {
static class Element implements Delayed{
long expireTime;
String msg;
public Element(long expireTime, String msg){
this.expireTime = expireTime;
this.msg = msg;
}
@Override
public long getDelay(TimeUnit unit) {
return unit.convert(this.expireTime - System.currentTimeMillis(), TimeUnit.MILLISECONDS);
}
@Override
public int compareTo(Delayed o) {
return (int) (this.getDelay(TimeUnit.MILLISECONDS) -o.getDelay(TimeUnit.MILLISECONDS));
}
}
public static void main(String[] args) {
DelayQueue delayQueue = new DelayQueue();
long now = System.currentTimeMillis();
delayQueue.add(new Element(now + 1000, "1"));
delayQueue.add(new Element(now + 2000, "2"));
delayQueue.add(new Element(now + 3000, "3"));
while(!delayQueue.isEmpty()){
try{
Element e = (Element) delayQueue.take();
System.out.println(e.msg);
}catch(InterruptedException e){
e.printStackTrace();
}
}
}
}
```
- asD
- Java
- Java基礎
- Java編譯器
- 反射
- collection
- IO
- JDK
- HashMap
- ConcurrentHashMap
- LinkedHashMap
- TreeMap
- 阻塞隊列
- java語法
- String.format()
- JVM
- JVM內存、對象、類
- JVM GC
- JVM監控
- 多線程
- 基礎概念
- volatile
- synchronized
- wait_notify
- join
- lock
- ThreadLocal
- AQS
- 線程池
- Spring
- IOC
- 特性介紹
- getBean()
- creatBean()
- createBeanInstance()
- populateBean()
- AOP
- 基本概念
- Spring處理請求的過程
- 注解
- 微服務
- 服務注冊與發現
- etcd
- zk
- 大數據
- Java_spark
- 基礎知識
- Thrift
- hdfs
- 計算機網絡
- OSI七層模型
- HTTP
- SSL
- 數據庫
- Redis
- mysql
- mybatis
- sql
- 容器
- docker
- k8s
- nginx
- tomcat
- 數據結構/算法
- 排序算法
- 快排
- 插入排序
- 歸并排序
- 堆排序
- 計算時間復雜度
- leetcode
- LRU緩存
- B/B+ 樹
- 跳躍表
- 設計模式
- 單例模式
- 裝飾者模式
- 工廠模式
- 運維
- git
- 前端
- thymeleaf
- 其他
- 代碼規范
- work_project
- Interview