当前位置:网站首页>阻塞队列与线程池原理
阻塞队列与线程池原理
2022-08-10 09:37:00 【每天都要喜滋滋】
阻塞
- 取值时,队列为空,取不到阻塞
- 存值时,队列已满,放不进去而阻塞
BlockingQueue
- add 非阻塞 向一个满的队列里存元素失败时会抛出异常
- remove非阻塞 向一个空的队列里取元素失败时会抛出异常
- offer 向一个满的队列里存元素失败时会返回false
- poll 向一个空的队列里取元素失败时会返回null
- take 阻塞
- put 阻塞
阻塞队列
- ArrayBlockingQueue:一个由数组结构组成的有界阻塞队列。
- Linked BlockingQueue:一个由链表结构组成的有界阻塞队列。
- PriorityBlockingQueue:一个支持优先级排序的无界阻塞队列。
- DelayQueue:一个使用优先级队列实现的无界阻塞队列。
- SynchronousQueue:一个不存储元素的阻塞队列。
- LinkedTransferQueue:一个由链表结构组成的无界阻塞队列。
- LinkedBlockingDeque:一个由链表结构组成的双向阻塞队列。
线程池
- Executor interface
- ExecutorService interface
- ThreadPoolExecutor class
- execute() 不关心返回结果
- submit() 关心返回结果
- shutdown() 尝试关闭一个线程,当前没有执行任务的线程,进行中断
- shutdownNow() 不管当前任务有无执行线程,都尝试进行中断
public ThreadPoolExecutor(int corePoolSize,
int maximumPoolSize,
long keepAliveTime,
TimeUnit unit,
BlockingQueue<Runnable> workQueue,
ThreadFactory threadFactory,
RejectedExecutionHandler handler) {
}
任务特性,cpu密集型、IO密集型、混合型
maximumPoolSize:cpu密集型 ,不要超过CPU的核心数 ,最多+1 Runtime.getRuntime().availableProcessors()
maximumPoolSize:IO密集型(磁盘和网络) ,CPU的核心数x2

边栏推荐
- 【数据仓库】什么是 Azure Synapse,它与 Azure Data Bricks 有何不同?
- 以技术御风险,护航云原生 | 同创永益 X 博云举办产品联合发布会
- 数据中台解决方案及未来发展方向
- 【物联网架构】最适合物联网的开源数据库
- 钻石价格预测的ML全流程!从模型构建调优道部署应用!
- shell之函数和数组
- Defending risks with technology and escorting cloud native | Tongchuang Yongyi X Boyun held a joint product launch conference
- J9 Number Theory: Macro Analysis of DAO Characteristics
- Oracle rac所在的网络要割接,停掉其中一个rac节点,这种方案可行吗?
- 细说Redis监控和告警
猜你喜欢

「微服务架构」编曲与编舞——让系统协同工作的不同模式
![[Internet of Things Architecture] The most suitable open source database for the Internet of Things](/img/e9/10cf128dec3000daf7a3b2c816588f.jpg)
[Internet of Things Architecture] The most suitable open source database for the Internet of Things

傅立叶级数与傅里叶变换

关于判断单峰数组的几种方法

CTFSHOW七夕杯web

【数据仓库】什么是 Azure Synapse,它与 Azure Data Bricks 有何不同?

腾讯发布四足机器人 Max 二代版本,梅花桩上完成跳跃、空翻

UE4 Sequence添加基础动画效果 (05-蓝图触发Sequence)

IDEA中xml文件头报错:URI is not registered (Settings | Languages & Frameworks | Schemas and DTDs)
![[Metaverse Omi Says] Listen to how Rabbit Fan Rabbit creates a new era of trendy play from virtual to reality](/img/e8/f431a9c932e0fa5f413b1f7e09bf46.png)
[Metaverse Omi Says] Listen to how Rabbit Fan Rabbit creates a new era of trendy play from virtual to reality
随机推荐
【REST架构】OData、JsonAPI、GraphQL 有什么区别?
原型和原型链
08 【Props 组件事件】
shell------常用小工具,sort,uniq,tr,cut
幂次方(暑假每日一题 20)
BUUCTF【pwn】解题记录(4-6页持续更新中)
Flink运行时架构 完整使用 (第四章)
1 活动时间与安排
JWT: To own me is to have power
细说Redis监控和告警
CTFSHOW七夕杯web
90.(cesium之家)cesium高度监听事件
J9 Digital Theory: What kind of sparks will Web3.0+ Internet e-commerce cause?
Message Queuing Overview
因子分析(SPSS)
Basic concepts, structures, and classes of thread pools
【软考 系统架构设计师】案例分析⑥ Web应用系统架构设计
npm i安装报错
How to break the DeepFake face-changing scam?turn him over
多线程知识点总结之温故而知新