package com.butterfly.thread;
public class ThreadCount {
private static int w = 50; // wait time
private static int c = 5;// service time
private static float u = 0.2f; // cpu 使用率 即20%
public static void main(String[] args) {
System.out.println(getOptimalCount());
}
// 获取最优的线程数量
public static int getOptimalCount() {
int count = (int) (Runtime.getRuntime().availableProcessors() * u * (1 + w / c));
return count;
}
}