当前位置:网站首页>线程池总结
线程池总结
2022-08-09 06:29:00 【史上最强的弟子】
线程池
new ThreadPoolExecutor(int corePoolSize, //核心线程数
int maximumPoolSize,//最大线程数
long keepAliveTime,//活跃时间
TimeUnit unit,//活跃时间单位
BlockingQueue<Runnable> workQueue,//阻塞队列
ThreadFactory threadFactory,//线程创建工厂
RejectedExecutionHandler handler);//拒绝策略
一开始让线程池执行,线程池会创建线程直到核心线程数,多余的线程会放到阻塞队列中,阻塞队列满了,创建线程直到最大线程数,当达到最大线程数,阻塞队列也满了的情况想继续执行,会促发拒绝策略。
拒绝策略:
1.直接抛异常.
2.直接return.
3.阻塞队列中最久没执行的return,新的插入队列.
4.调用线程内部处理.
怎么设置核心线程数和最大线程数
1.首先查看CPU 是计算密集型还是I/O 密集型。
计算密集型 = 核心数
I/O密集型 = 2n
公式
x 是响应系数
n/(1-x)
1.当cpu是I/O 密集型时,则 x ≈ 0.5 ,2n
2.当cpu是计算密集型时,则 x ≈ 0 ,n
最大线程数是核心线程数2倍
边栏推荐
- 普罗米修斯原理及节点发布
- .NET高级技术
- pycharm环境包导入到另外一个环境
- db.sqlite3 has no "as Data Source" workaround
- Error jinja2.exceptions.UndefinedError: 'form' is undefined
- 什么是excel文件保护
- [GO], arrays and slices
- C language implements sequential stack and chain queue
- PDF不能打印和复制的问题如何解决?
- 报错:flask: TypeError: ‘function‘ object is not iterable
猜你喜欢

Import the pycharm environment package into another environment

代码目录结构
![[GO], arrays and slices](/img/71/86126c41d0f43aa8b9f232b219f5d7.png)
[GO], arrays and slices

MYSQL Advanced Chapter - Query Interception Analysis, Lock Mechanism, Master-Slave Replication
![[MySQL] Second, the relationship between processes, MySQL password cracking, table building and database building related commands](/img/20/a0fb44e9360837146d0ed696c9e992.png)
[MySQL] Second, the relationship between processes, MySQL password cracking, table building and database building related commands

锁执行的过程

mongo+ycsb性能测试及线程数分析

字节跳动笔试题2020 (抖音电商)

Output method of list string print(*a) print(““.join(str(c) for c in a) )

普罗米修斯原理及节点发布
随机推荐
tidb crash test
zip压缩包密码解密
P6阿里机试题之2020 斐波那契数
workbench 数据导出
XxlJobConfig分布式定时器任务管理XxlJob配置类,替代
Search 1688 product interface by image (item_search_img-search 1688 product by image (Politao interface) code docking tutorial
Simple to use Lambda expressions
Data center project preliminary summary
ZIP压缩包文件删除密码的方法
【Feel】In the Unity Feel plugin, Camera cannot display CameraShake correctly
Unity五子棋游戏设计 和简单AI实现(1)
Silently start over, the first page is also a new page
Qt 学习(三) —— Qt 模块
按图搜索1688商品接口(item_search_img-按图搜索1688商品(拍立淘接口)代码对接教程
PDF不能打印和复制的问题如何解决?
VS2019 common shortcut keys
中英文说明书丨TRC D-阿卓糖(D-Altrose)
字节跳动笔试题2020 (抖音电商)
Excel受保护的工作表怎么操作?
kubernetes security