Here you can find the source of getQueuedThreadPool(double threadToCpuRatio, int queueCapacity)
Parameter | Description |
---|---|
threadToCpuRatio | - for example, assuming you have 2 CPUs and setting a threadToCpuRation to 3, the result will be a pool with 6 working threads. |
public static ExecutorService getQueuedThreadPool(double threadToCpuRatio, int queueCapacity)
//package com.java2s; //License from project: Open Source License import java.util.concurrent.ExecutorService; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; public class Main { private static final int NUM_CPU = Runtime.getRuntime().availableProcessors(); /**/* w w w. j a va 2s. com*/ * @param threadToCpuRatio - for example, assuming you have 2 CPUs and setting a threadToCpuRation to 3, the result will be a pool with 6 working threads. * @return an {@link ExecutorService} with defined amount of worker thread for each CPUm A {@link SynchronousQueue} and a {@link ThreadPoolExecutor.CallerRunsPolicy} */ public static ExecutorService getQueuedThreadPool(double threadToCpuRatio, int queueCapacity) { int workingThreads = Double.valueOf(NUM_CPU * threadToCpuRatio).intValue(); return new ThreadPoolExecutor(workingThreads, workingThreads, 60, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(queueCapacity), new ThreadPoolExecutor.CallerRunsPolicy()); } }