当前位置:网站首页>线程池总结
线程池总结
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倍
边栏推荐
- Fragments
- Unity五子棋游戏设计 和简单AI实现(1)
- 默默重新开始,第一页也是新的一页
- Unity backgammon game design and simple AI implementation (1)
- 报错jinja2.exceptions.UndefinedError: ‘form‘ is undefined
- 抗菌药物丨Toronto Research Chemicals 天冬酰胺D
- GNNExplainer应用于节点分类任务
- Remember a nest.js route that matches all the path problems that follow
- 22 high mid term paper topics forecast
- P6阿里机试题之2020 斐波那契数
猜你喜欢
db.sqlite3 has no "as Data Source" workaround
C语言实现顺序栈和链队列
字节跳动面试题之镜像二叉树2020
workbench 数据导出
C language implements sequential stack and chain queue
db.sqlite3没有“as Data Source“解决方法
2022-08-08: Given an array arr, it represents the height of the missiles that will appear in order from morning to night.When the cannon shoots missiles, once the cannon is set to shoot at a certain h
推进产教融合 赋能教育创新发展 | 华云数据荣获“企业贡献奖”
关于如何查找NXP S32K1xx系列单片机的封装信息和引脚定义
Search 1688 product interface by image (item_search_img-search 1688 product by image (Politao interface) code docking tutorial
随机推荐
Introduction of convenient functions and convenient shortcut keys of vs tomato assistant
Invalid argument(s) appears when redis runs lua script
报错:FSADeprecationWarning: SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and will be disab
redis 运行lua 脚本 出现Invalid argument(s)
phpstudy install flarum forum
中英文说明书丨CalBioreagents ACTH N端单克隆抗体
Silently start over, the first page is also a new page
像天才一样思考:如何培养自己的创造力?
[GO], arrays and slices
kubernetes security
字节跳动笔试题2020 (抖音电商)
The singleton pattern
GNNExplainer应用于节点分类任务
DDD 领域驱动设计
install flask
22 high mid term paper topics forecast
【R语言】交互作用 测试数据
力扣刷题180
ZIP压缩包文件删除密码的方法
io.lettuce.core.RedisCommandTimeoutException Command timed out