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;bailout
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