当前位置:网站首页>阻塞队列LinkedBlockingQueue 源码解析
阻塞队列LinkedBlockingQueue 源码解析
2022-07-28 06:45:00 【trigger333】
目录
BlockingQueue的实现有很多,下面主要介绍下LinkedBQ。

构造方法
默认的容量是 integer最大值

linkedBQ里面用的是 单向链表

添加元素
put

offer的实现和ArrayBQ差不多
阻塞队列ArrayBlockingQueue 源码解析_trigger333的博客-CSDN博客
拉取元素
和添加相对应
poll对应offer, take对应put。

和ArrayBQ的区别
LinkedBQ 是链表,ArrayBQ是数组,在频繁添加的时候LinkedBQ 需要创建节点,而ArrayBQ直接添加即可,在频繁删除时LinkedBQ的节点会自己指向自己去 help GC,而ArrayBQ只需要将操作index即可,所以在单一操作较多时,ArrayBQ的添加和删除性能更高,如果既有添加也有删除,那么LinkedBQ 这两种操作是互不干扰的,而ArrayBQ时只能添加或者只能删除。
LinkedBQ 里面有两个锁,一个是putLock,一个是takeLock,也有两个Condition,也就是在put元素的时候如果里面本身就有元素的话,是不会影响到take的,只是当链表中元素从0变为1 的时候会通知等待的take线程。同理take也不会影响到put。
而ArrayBQ里面只有一把锁lock和两个Condition,put的时候不能take,take 的时候不能put。
所以LinkedBQ在多线程的生产者和消费者模式下的吞吐量会更大。
具体实验可参照
Java线程池实验:ArrayBlockingQueue和LinkedBlockingQueue吞吐量测试_trigger333的博客-CSDN博客
Java线程池实验:ArrayBlockingQueue和LinkedBlockingQueue性能测试_trigger333的博客-CSDN博客_arrayblockqueue 测试
边栏推荐
- Find out whether the number exists from the matrix
- [book club issue 13] Chapter 1 multimedia processing tools ffmpeg tools
- Tell you step by step what you need to do to apply for PMP? What should I do?
- Solve the inherent defects of CNN! Common CNN architecture ccnn is coming | icml2022
- Melt cloud x chat, create a "stress free social" habitat with sound
- C#,入门教程——程序运行时的调试技巧与逻辑错误探针技术与源代码
- Prescan quick start to proficient in lecture 17, speed curve editor
- Mysql, how can we get the number of rows affected by the query?
- Spiral matrix
- leetcode/单词长度的最大乘积
猜你喜欢

Some experience of gd32 using Hal Library of ST and Gd official library

Understand the propagation process of EMI electromagnetic interference through five diagrams - the influence of square wave steepness on high-frequency components, the spectrum graph from time sequenc

XSS知识点和20字符短域名绕过

Mysql-怎么添加用户和设置权限?
![[pyqt] pyqt development experience_ How to find events and methods of controls](/img/40/7597d6413c88793e22276325d5f602.png)
[pyqt] pyqt development experience_ How to find events and methods of controls

Draw.io image saving path settings

一键开关机电路

网口网络水晶头RJ45、POE接口定义线序

Es6: arrow function usage

Basic dictionary of deep learning --- activation function, batch size, normalization
随机推荐
leetcode/单词长度的最大乘积
Puzzle (004.3) pattern puzzle
[book club issue 13] Chapter 2 notes on the packaging format and coding format of video files
Chairman tree review
Viewing vantage's self drive from the "three good" kitchen electricity standard and the value proposition of "serious life"
Understand the propagation process of EMI electromagnetic interference through five diagrams - the influence of square wave steepness on high-frequency components, the spectrum graph from time sequenc
[event registration] cloud native technology exchange meetup, see you in Guangzhou on August 6
How to close the blocked program process?
MySQL query error [err] 1046 - no database selected
What if the computer folder cannot be renamed?
Mechanical revolution Jiaolong P wired network card driver can't play
QT 怎么删除布局里的所有控件?
一篇文章搞懂数据仓库:元数据分类、元数据管理
Use of namespaces
EMC EMI磁珠的特性
How do we run batch mode in MySQL?
New generation cloud native message queue (II)
Get the clicked line number in qtablewidget
How to set it to pop up the right-click menu
sparksql 与flinksql 建表 与 连表记录