最近在看并发编程的知识,比如ConcurrentHashMap、ReentrantLock等知识,现在分析一下LinkedBlockingQueue的原理
在学习JAVA集合的时候,应该都学习过LinkedList和ArrayList,二者的区别是底层实现数据结构不一样,LinkedList是通过链表实现的,ArrayList是通过数组实现的。所以相对于基本集合类来说,LinkedBlockingQueue和相对应的ArrayBlockingQueue一样,底层数据结果不一样,LinkedBlockingQueue和LinkedList一样,内部是基于链表来存放元素,而ArrayBlockingQueue则和ArrayList一样,内部是基于数组来存放元素的。
LinkedBlockingQueu实现了BlockingQueue接口,下面可以看一下简单的关系继承图,LinkedBlockingQueue是通过继承AbstractQueue抽象类和实现BlockingQueue
LinkedBlockingQueue不同于ArrayBlockingQueue,它如果不指定容量,默认是Integer.MAX_VALUE大小,如下代码
public LinkedBlockingQueue() {
this(2147483647);//Integer.MAX_VALUE = 2147483647
}
public LinkedBlockingQueue(int var1) {
this.count = new AtomicInteger();
this.takeLock = new ReentrantLock();
this.notEmpty = this.takeLock.newCondition();
this.putLock = new ReentrantLock();
this.notFull = this.putLock.newCondition();
if (var1 <= 0) {
throw new IllegalArgumentException();
} else {
this.capacity = var1;
this.last = this.head = new LinkedBlockingQueue.Node((Object)null);
}
}
本文地址:https://blog.csdn.net/qq_19940807/article/details/107578928
如对本文有疑问, 点击进行留言回复!!
Flink程序JDK8 运行一段时间后NullException解决
解决: java.lang.NoClassDefFoundError: org/apache/http/client/HttpClient
SpringBoot中定制异常页面(404页面配置提高用户体验)
DataGrip和IDEA无法连接上Mysql问题解决方法详解
Java基础语法(多态、类、接口、Date类、基本类型、系统类)
网友评论