javaio线程池_IO密集型的线程池大小设置

更新时间:2023-07-16 22:15:52 阅读: 评论:0

javaio线程池_IO密集型的线程池⼤⼩设置
类型判断(CPU密集orIO密集or混合型)善意的谎言
看应⽤是CPU密集型的还是IO密集型的,还是混合型的。
CPU密集 CPU密集型的话,⼀般配置CPU处理器个数+/-1个线程,所谓CPU密集型就是指系统⼤部分时间是在做程序正常的计算任务,例如数字运算、赋值、分配内存、内存拷贝、循环、查找、排序等,这些处理都需要CPU来完成。
IO密集 IO密集型的话,是指系统⼤部分时间在跟I/O交互,⽽这个时间线程不会占⽤CPU来处理,即在这个时间范围内,可以由其他线程来使⽤CPU,因⽽可以多配置⼀些线程。
混合型 混合型的话,是指两者都占有⼀定的时间。
IO密集型线程⼤⼩
/**
* Support class for thread pool size天的笔画>特立独行的人
*
* @author Nadeem Mohammad
*
*/
你很特别绘本故事public final class ThreadPoolUtil {
private ThreadPoolUtil() {
}
/**
* Each tasks blocks 90% of the time, and works only 10% of its
*lifetime. That is, I/O intensive pool
* @return io intesive Thread pool size
什么叫绘本*/
死神高清壁纸public static int ioIntesivePoolSize() {
明艳的近义词>海马的功效与作用吃法
double blockingCoefficient = 0.9;
return poolSize(blockingCoefficient);
}
/**
*
* Number of threads = Number of Available Cores / (1 - Blocking
* Coefficient) where the blocking coefficient is between 0 and 1.
*
* A computation-intensive task has a blocking coefficient of 0, whereas an
* IO-intensive task has a value clo to 1,
* so we don't have to worry about the value reaching 1.
* @param blockingCoefficient the coefficient
* @return Thread pool size
*/
public static int poolSize(double blockingCoefficient) {
int numberOfCores = Runtime().availableProcessors();
int poolSize = (int) (numberOfCores / (1 - blockingCoefficient));
return poolSize;
}
}
使⽤
ExecutorService executorService = wFixedThreadPool(ThreadPoolUtil.ioIntesivePoolSize());这样语义化设置,表达能⼒强⼀些。
doc

本文发布于:2023-07-16 22:15:52,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/89/1084283.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

上一篇:l配置详解
下一篇:IGBT图解
标签:时间   密集型   线程   密集   功效   部分
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图