Java Thread Executor Pool createClientThreadPool(int numThreads, int queueSize)

Here you can find the source of createClientThreadPool(int numThreads, int queueSize)

Description

This creates the client side thread pool for WXS.

License

Open Source License

Parameter

Parameter Description
numThreads The desired number of threads in the pool.

Declaration

private static ExecutorService createClientThreadPool(int numThreads,
        int queueSize) 

Method Source Code

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

Related

  1. clearPreloadThreads()
  2. createBoundedCachedThreadPool( final int corePoolSize, final int maximumPoolSize, final long keepAliveTime, final TimeUnit timeUnit)
  3. createPool(int threads, int queueSize)
  4. createPooledExecutorService(int poolSize, final String namePrefix)
  5. getPool()
  6. getPool()