1 package com.github.dexecutor.executor.support; 2 3 /** 4 * 5 * @author Nadeem Mohammad 6 * 7 */ 8 public final class ThreadPoolUtil { 9 10 private ThreadPoolUtil() { 11 12 } 13 /** 14 * Each tasks blocks 90% of the time, and works only 10% of its 15 * lifetime. That is, I/O intensive pool 16 * @return io intesive Thread pool size 17 */ 18 public static int ioIntesivePoolSize() { 19 20 double blockingCoefficient = 0.9; 21 return poolSize(blockingCoefficient); 22 } 23 24 /** 25 * 26 * Number of threads = Number of Available Cores / (1 - Blocking 27 * Coefficient) where the blocking coefficient is between 0 and 1. 28 * 29 * A computation-intensive task has a blocking coefficient of 0, whereas an 30 * IO-intensive task has a value close to 1, 31 * so we don't have to worry about the value reaching 1. 32 * @param blockingCoefficient 33 * @return Thread pool size 34 */ 35 public static int poolSize(double blockingCoefficient) { 36 int numberOfCores = Runtime.getRuntime().availableProcessors(); 37 int poolSize = (int) (numberOfCores / (1 - blockingCoefficient)); 38 return poolSize; 39 } 40 }