当前位置:网站首页>如何合理地估算线程池大小
如何合理地估算线程池大小
2022-07-23 19:06:00 【InfoQ】
CPU密集型
public class SrcTest {
static int threadNum = 20;
final static int taskNum = 200;
static ExecutorService executorService = Executors.newFixedThreadPool(threadNum);
static CountDownLatch endGate = new CountDownLatch(taskNum);
public static void main(String[] args) throws InterruptedException {
long start = System.currentTimeMillis();
for (int i = 0; i< taskNum; i++){
executorService.submit(cpuCal());
}
endGate.await();
long end = System.currentTimeMillis();
System.out.println("线程池数量:"+threadNum+" CPU核数:"+Runtime.getRuntime().availableProcessors()+"全部结束:time:"+(end-start));
}
public static Thread cpuCal(){
return new Thread(()->{
long start = System.currentTimeMillis();
//随便写个cpu耗时的操作
for (int i = 0;i<10000000;i++){
StringBuffer sb = new StringBuffer();
sb.append(i).append(",");
}
long end = System.currentTimeMillis();
System.out.println("线程ID:"+Thread.currentThread().getId()+"; 消耗时间:"+(end-start));
endGate.countDown();
});
}
}
执行结果








图标结果

sysctl hw.physicalcpusysctl hw.logicalcpu得出结论
IO密集型
实验(略)
混合型
为什么线程上下文切换的时候会耗费性能
上下文切换的概念
上下文切换带来的损耗
参考文档

边栏推荐
- Top ten shrinking industries in China in the first half of 2022
- 最新版Confluence+Docker+MySQL8部署教程
- Leetcode 216. 组合总和 III
- R language uses the gather function of tidyr package to convert a wide table to a long table (wide table to long table), the first parameter specifies the name of the new data column generated from th
- The numerical sequence caused by the PostgreSQL sequence cache parameter is discontinuous with interval gap
- Principe de l'énergie et méthode variationnelle note 19: principe de l'énergie résiduelle minimale + principe du travail possible
- Edge cloud | 1. overview
- AtCoder B - Pizza
- 21. Mix in details
- Meiker Studio - Huawei 14 day Hongmeng equipment development practical notes 5
猜你喜欢

梅科尔工作室-华为14天鸿蒙设备开发实战笔记六

Leetcode 219. duplicate Element II exists (yes, resolved)

phar反序列化

Energy principle and variational method note 12: minimum potential energy principle

Leetcode 228. summary interval (yes, solved)

QT下assimp库的模型加载

安装Win11找不到固态硬盘如何解决?

Cannot read properties of null (reading ‘pickAlgorithm‘)

New product listing | A-share floor derivatives market point

osgearth2.8编译siverlining云效果
随机推荐
MySQL master-slave replication
搭建自己的目标检测环境,模型配置,数据配置 MMdetection
使用Jmeter和VisualVW进行压测准备
Edge cloud | 1. overview
Leetcode 209. 长度最小的子数组
R language uses the quantile function to calculate the quantile (percentile) of vector data or dataframe to specify the data column
最新版Confluence+Docker+MySQL8部署教程
编译器LLVM-MLIR-Intrinics-llvm backend-instruction
Set asp Net MVC site default page is the specified page
Odrive application 6 encoder
Top ten shrinking industries in China in the first half of 2022
Attack and defense world web question Fakebook
[interview: concurrent Article 22 multithreading: reentrantlock]
小程序頭像組樣式
Win11小组件怎么添加待办事项?Win11添加待办事项小组件的方法
【Unity项目实践】关卡解锁
osgearth2.8编译siverlining云效果
QT with OpenGL (frame cache)
3D point cloud course (VII) -- feature point description
Viewing the "Empathy" energy of iqoo 10 pro from 200W super flash charging