应该如何设置线程池大小
根据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密集型任务,设置大小为:
线程

本文探讨了如何确定Java线程池的大小,针对CPU密集型和IO密集型任务给出了计算公式,并通过实际测试验证了IO密集型任务线程池的性能。测试结果显示线程执行时间和等待时间存在一定的关系,暗示了线程调度的优化可能影响了任务执行。
最低0.47元/天 解锁文章

被折叠的 条评论
为什么被折叠?



