/** * Return a capped {@link BalancingThreadPoolExecutor} with the given * maximum number of threads and target utilization. The default smoothing * weight and balance after constants are used. * * @param maxThreads maximum number of threads to use * @param targetUtilization a float between 0.0 and 1.0 representing the * percentage of the total CPU time to be used by * this pool */ public static BalancingThreadPoolExecutor newBalancingThreadPoolExecutor(int maxThreads, float targetUtilization) { return newBalancingThreadPoolExecutor(maxThreads, targetUtilization, DEFAULT_SMOOTHING_WEIGHT, DEFAULT_BALANCE_AFTER); }
/** * Return a capped {@link BalancingThreadPoolExecutor} with the given * maximum number of threads, target utilization, smoothing weight, and * balance after values. * * @param maxThreads maximum number of threads to use * @param targetUtilization a float between 0.0 and 1.0 representing the * percentage of the total CPU time to be used by * this pool * @param smoothingWeight smooth out the averages of the CPU and wait time * over time such that tasks aren't too heavily * skewed with old or spiking data * @param balanceAfter balance the thread pool after this many tasks * have run */ public static BalancingThreadPoolExecutor newBalancingThreadPoolExecutor(int maxThreads, float targetUtilization, float smoothingWeight, int balanceAfter) { ThreadPoolExecutor tpe = new ThreadPoolExecutor(1, maxThreads, 60L, TimeUnit.SECONDS, new SynchronousQueue<Runnable>(), new CallerBlocksPolicy()); return newBalancingThreadPoolExecutor(tpe, targetUtilization, smoothingWeight, balanceAfter); }
TaskServiceIterable taskIterable = new TaskServiceIterable(taskService); ExecutorService workerExecutorService = StrategicExecutors.newBalancingThreadPoolExecutor( new ThreadPoolExecutor( configuration.getInt(QSConfig.PROP_WORKER_POOL_CORE),