Here you can find the source of createClientThreadPool(int numThreads, int queueSize)
Parameter | Description |
---|---|
numThreads | The desired number of threads in the pool. |
private static ExecutorService createClientThreadPool(int numThreads, int queueSize)
//package com.java2s; //All Rights Reserved * Licensed Materials - Property of IBM import java.util.concurrent.ExecutorService; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; public class Main { /**/*from w w w . jav a2 s. co m*/ * This creates the client side thread pool for WXS. This uses a CallerRunsPolicy so that when clients are * preloading the grid, we don't end up queueing lots of preload agent calls. This leads to an out of memory * situation quickly because the client keeps fetching from the backend, makings lots of objects for that state and * sending it to the threadpool where it just builds up. * * @param numThreads * The desired number of threads in the pool. * @return */ private static ExecutorService createClientThreadPool(int numThreads, int queueSize) { // this means that once there are 3x numThreads jobs queued waiting for // a thread then it will start running jobs on the submitting thread. LinkedBlockingQueue<Runnable> queue = new LinkedBlockingQueue<Runnable>( queueSize); // Once the queue reports that it is full, the CallerRunPolicy will run jobs // on the submitter thread. ExecutorService p = new ThreadPoolExecutor(numThreads, numThreads, 2L, TimeUnit.MINUTES, queue, new ThreadPoolExecutor.CallerRunsPolicy()); return p; } }