java 线程池最优数量计算

发布时间:2022-04-21 14:49:14
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;
	}
}


Card image cap
APP STORE
Card image cap
应用宝
Card image cap
小米
Card image cap
华为