Java Thread Executor Pool getQueuedThreadPool(double threadToCpuRatio, int queueCapacity)

Here you can find the source of getQueuedThreadPool(double threadToCpuRatio, int queueCapacity)

Description

get Queued Thread Pool

License

Open Source License

Parameter

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.

Return

an with defined amount of worker thread for each CPUm A and a

Declaration

public static ExecutorService getQueuedThreadPool(double threadToCpuRatio, int queueCapacity) 

Method Source Code


//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());
    }
}

Related

  1. createClientThreadPool(int numThreads, int queueSize)
  2. createPool(int threads, int queueSize)
  3. createPooledExecutorService(int poolSize, final String namePrefix)
  4. getPool()
  5. getPool()
  6. getRecheckThreadPool()
  7. getThreadPool()
  8. getThrealPool()
  9. getTightThreadPool()