Java 如何确定线程池大小及其IO密集型公式验证(未完)

本文探讨了如何确定Java线程池的大小,针对CPU密集型和IO密集型任务给出了计算公式,并通过实际测试验证了IO密集型任务线程池的性能。测试结果显示线程执行时间和等待时间存在一定的关系,暗示了线程调度的优化可能影响了任务执行。
摘要由CSDN通过智能技术生成

应该如何设置线程池大小

根据IBM提供的设置建议

The optimum size of a thread pool depends on the number of processors available and the nature of the tasks on the work queue. On an N-processor system for a work queue that will hold entirely compute-bound tasks, you will generally achieve maximum CPU utilization with a thread pool of N or N+1 threads.
For tasks that may wait for I/O to complete – for example, a task that reads an HTTP request from a socket – you will want to increase the pool size beyond the number of available processors, because not all threads will be working at all times. Using profiling, you can estimate the ratio of waiting time (WT) to service time (ST) for a typical request. If we call this ratio WT/ST, for an N-processor system, you’ll want to have approximately N(1+WT/ST)* threads to keep the processors fully utilized.

可以得出:
对于CPU密集型任务,设置大小为&

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值