Java ThreadPoolExecutor createQueue(final int queueCapacity)

Here you can find the source of createQueue(final int queueCapacity)

Description

Create the BlockingQueue to use for the ThreadPoolExecutor.

License

Apache License

Parameter

Parameter Description
queueCapacity the specified queue capacity

Return

the BlockingQueue instance

Declaration

private static BlockingQueue<Runnable> createQueue(final int queueCapacity) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.concurrent.BlockingQueue;

import java.util.concurrent.LinkedBlockingQueue;

import java.util.concurrent.SynchronousQueue;

public class Main {
    /**/*from  w  w  w  .j  a  va 2  s . c  o m*/
     * Create the BlockingQueue to use for the ThreadPoolExecutor.
     * <p>
     * A LinkedBlockingQueue instance will be created for a positive capacity
     * value; a SynchronousQueue else.
     *
     * @param queueCapacity
     *            the specified queue capacity
     * @return the BlockingQueue instance
     * @see java.util.concurrent.LinkedBlockingQueue
     * @see java.util.concurrent.SynchronousQueue
     */
    private static BlockingQueue<Runnable> createQueue(final int queueCapacity) {
        if (queueCapacity > 0) {
            return new LinkedBlockingQueue<Runnable>(queueCapacity);
        }
        return new SynchronousQueue<Runnable>();
    }
}

Related

  1. createExecutor()
  2. createExecutor(final String name, int count, int keepAlive, final boolean isDaemon)
  3. createScheduledThreadPoolExecutor(final int poolSz, final String threadName)
  4. createThreadPoolExecutor(final int queueSize, final String threadName)
  5. executeInBackground(Runnable r)
  6. executeInDaemon(Runnable... run)