当前位置:网站首页>线程池总结
线程池总结
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倍
边栏推荐
- 安装flask
- APP product source data interface (taobao, jingdong/spelling/suning/trill platform details a lot data analysis interface) code and docking tutorial
- 中英文说明书丨TRC D-阿卓糖(D-Altrose)
- Gao Zelong, a famous digital collection expert and founder of the Digital Collection Conference, was interviewed by China Entrepreneur Magazine
- 字节跳动面试题之镜像二叉树2020
- Simple to use Lambda expressions
- 数据库中间件-jdbi
- untiy countdown
- APP商品详情源数据接口(淘宝/京东/拼多多/苏宁/抖音等平台详情数据分析接口)代码对接教程
- VS2019常用快捷键
猜你喜欢
按图搜索1688商品接口(item_search_img-按图搜索1688商品(拍立淘接口)代码对接教程
治疗消化性溃疡—Toronto Research Chemicals 甘氨酸铝
[MySQL] Second, the relationship between processes, MySQL password cracking, table building and database building related commands
vs番茄助手的方便功能和便捷快捷键介绍
Unity 五子棋游戏设计和简单AI(2)
Altium designer软件常用最全封装库,包含原理图库、PCB库和3D模型库
Unity backgammon game design and simple AI implementation (1)
Data center project preliminary summary
报错:FSADeprecationWarning: SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and will be disab
网络学习总结
随机推荐
cut命令的使用实例
Altium designer软件常用最全封装库,包含原理图库、PCB库和3D模型库
GNNExplainer应用于节点分类任务
zip压缩包密码解密
思维方法 解决问题的能力
db.sqlite3 has no "as Data Source" workaround
Go lang1.18入门精炼教程——第一章:环境搭建
IQ Products巨细胞病毒CMV感染检测试剂盒的特征和应用
代码目录结构
22 high mid term paper topics forecast
The solution that does not work and does not take effect after VScode installs ESlint
常用Oracle命令
直接用的zip包 缺少很多依赖,pip没有,感觉用anaconda create一个环境会方便点
golang xml 处理动态属性
String.toLowerCase(Locale.ROOT)
运算放大器(OPA)超详细参数讲解-运放---以及8个型号的运算放大器分析对比
AD的library中 库文件后缀有.intlib .schlib .pcblib 的区别
mmdetection源码解析--ResNet18
Reverse Engineering
Ferric oxide/bismuth sulfide nanocomposites ([email protected]@BSABiS nanoparticles) | dendrimer-stabilized bismuth sulfide nanop