当前位置:网站首页>线程池总结
线程池总结
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倍
边栏推荐
- Altium designer软件常用最全封装库,包含原理图库、PCB库和3D模型库
- 逆向工程
- Reverse Engineering
- e-learning summary
- 锁执行的过程
- The singleton pattern
- Xilinx Zynq ZynqMP DNA
- untiy countdown
- Gao Zelong, a famous digital collection expert and founder of the Digital Collection Conference, was interviewed by China Entrepreneur Magazine
- tidb crash test
猜你喜欢
锁执行的过程
Unity五子棋游戏设计 和简单AI实现(1)
按图搜索1688商品接口(item_search_img-按图搜索1688商品(拍立淘接口)代码对接教程
sql问题解答创建表的语句
[GO], arrays and slices
Redis 2 - 高级
带头双向循环链表的增删查改(C语言实现)
变压器的工作原理(图解,原理图讲解,一看就懂)
Output method of list string print(*a) print(““.join(str(c) for c in a) )
How to find package information and pin definitions for NXP S32K1xx series microcontrollers
随机推荐
【Feel】In the Unity Feel plugin, Camera cannot display CameraShake correctly
语句加锁分析
static静态关键字和继承
idea中PlantUML插件使用
【R语言】把文件夹下的所有文件提取到特定文件夹
workbench 数据导出
Flask failed to create database without error
io.lettuce.core.RedisCommandTimeoutException Command timed out
力扣刷题180
Getting started with kubernetes apparmor
[R language] Normalize and organize files into folders of various file types
Deep Learning - Principles of Neural Networks 2
输入框最前面添加放大镜&&background-image和background-color冲突问题
思维方法 解决问题的能力
报错jinja2.exceptions.UndefinedError: ‘form‘ is undefined
install flask
Unity backgammon game design and simple AI implementation (1)
[MySQL] Second, the relationship between processes, MySQL password cracking, table building and database building related commands
[R language] Extract all files under a folder to a specific folder
shardingsphere data sharding configuration item description and example