当前位置:网站首页>How to reasonably estimate the size of thread pool
How to reasonably estimate the size of thread pool
2022-07-23 22:29:00 【InfoQ】
CPU intensive
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(" Number of thread pools :"+threadNum+" CPU Check the number :"+Runtime.getRuntime().availableProcessors()+" It's all over :time:"+(end-start));
}
public static Thread cpuCal(){
return new Thread(()->{
long start = System.currentTimeMillis();
// Write something about it cpu Time consuming operations
for (int i = 0;i<10000000;i++){
StringBuffer sb = new StringBuffer();
sb.append(i).append(",");
}
long end = System.currentTimeMillis();
System.out.println(" Threads ID:"+Thread.currentThread().getId()+"; Elapsed time :"+(end-start));
endGate.countDown();
});
}
}
Execution results








Icon results

sysctl hw.physicalcpusysctl hw.logicalcpuCome to the conclusion
IO intensive
experiment ( A little )
mixed type
Why does thread context switching cost performance
The concept of context switching
Loss caused by context switching
Reference documents

边栏推荐
- Storage structure and management disk. It's a bit like installing Win98. You need to partition and format the hard disk first
- About synchronizing data from computer to mobile
- Microsoft SQL Server数据库语言及功能使用(十三)
- Ali onedate's layered thought
- 产品生命周期,常见的项目职能,信息流 都是什么
- [golang learning notes] is parameter transfer in go language value transfer or reference transfer
- Array - 59. Spiral matrix II
- 如何在 pyqt 中实现桌面歌词
- Linked list - 203. remove linked list elements
- Programming in the novel [serial 19] the moon bends in the yuan universe
猜你喜欢

JDBC programming of MySQL
About synchronizing data from computer to mobile

除了钱,创业者还需要什么?专访明月湖创赛创投机构

糖尿病遗传风险检测挑战赛进阶

Leetcode high frequency question 62. different paths: how many paths does the robot have from the upper left corner to the lower right corner? Pure probability permutation and combination problem, not

Sudoku written for once and for all

el-select下拉框多选远程搜索反显

University database creation and query practice -- database table design

Preliminary discussion on POC compilation
![[mathematical modeling summer training] location of distribution center](/img/d5/c9b4de6750a7ed080c194250629467.png)
[mathematical modeling summer training] location of distribution center
随机推荐
QT set cache and compile output path
vip股票账户在手机开通安全吗?
[jailhouse article] a novel software architecture for mixed criticality systems (2020)
Introduction to I2C Principle & Application of esp32
人生总需要一点激情
Sixty final review questions of software architecture
年化收益率6%的理财产品
Comment forcer complètement le meurtre de processus indépendants de l'arrière - plan?
[problem handling] merge made by the 'ort' strategy
Programming in the novel [serial 19] the moon bends in the yuan universe
【golang学习笔记】包(package)的使用
【golang学习笔记】并发基础
JDBC programming of MySQL
Programming in the novel [serial 17] the moon bends in the yuan universe
LeetCode高频题53. 最大子数组和,具有最大和的连续子数组,返回其最大和
Cookies and sessions
Taobao assistant is disabled. What is the reason for using the big Taoying import data package to upload the baby prompt "the main image is required and cannot be empty"? How to solve it?
Programming in the novel [serial 16] the moon bends in the yuan universe
Wangxuegang video coding -- mediacodec coding and decoding
The ultimate experiment of OSPF -- learn the example of OSPF century template