Example usage for java.util.concurrent PriorityBlockingQueue PriorityBlockingQueue

List of usage examples for java.util.concurrent PriorityBlockingQueue PriorityBlockingQueue

Introduction

In this page you can find the example usage for java.util.concurrent PriorityBlockingQueue PriorityBlockingQueue.

Prototype

public PriorityBlockingQueue(Collection<? extends E> c) 

Source Link

Document

Creates a PriorityBlockingQueue containing the elements in the specified collection.

Usage

From source file:Main.java

/**
 * Creates a fixed priority thread pool.
 *//*www. j a va2 s  .c o  m*/
public static ExecutorService newPriorityThreadPool(String name, int numThreads) {
    return new ThreadPoolExecutor(numThreads, numThreads, 1, TimeUnit.SECONDS,
            new PriorityBlockingQueue<Runnable>(numThreads), newNamedThreadFactory(name));
}

From source file:com.fatwire.dta.sscrawler.RenderingThreadPool.java

public RenderingThreadPool(final int threadSize) {
    super(threadSize, threadSize, 60, TimeUnit.SECONDS, new PriorityBlockingQueue<Runnable>(5000));

}

From source file:actor4j.core.DefaultActorThread.java

public DefaultActorThread(ActorSystemImpl system) {
    super(system);

    directiveQueue = new MpscArrayQueue<>(system.getQueueSize());
    priorityQueue = new PriorityBlockingQueue<>(system.getQueueSize());
    serverQueueL2 = new MpscArrayQueue<>(system.getQueueSize());
    serverQueueL1 = new ArrayDeque<>(system.getBufferQueueSize());
    outerQueueL2 = new MpscArrayQueue<>(system.getQueueSize());
    outerQueueL1 = new ArrayDeque<>(system.getBufferQueueSize());
    innerQueue = new CircularFifoQueue<>(system.getQueueSize());

    newMessage = new AtomicBoolean(true);
}

From source file:actor4j.core.XActorThread.java

public XActorThread(ActorSystemImpl system) {
    super(system);

    directiveQueue = new MpscArrayQueue<>(system.getQueueSize());
    priorityQueue = new PriorityBlockingQueue<>(system.getQueueSize());
    serverQueueL2 = new MpscArrayQueue<>(system.getQueueSize());
    serverQueueL1 = new ArrayDeque<>(system.getBufferQueueSize());
    outerQueueL2B = new MpscLinkedQueue8<>();
    outerQueueL2A = new MpscArrayQueue<>(system.getQueueSize());
    outerQueueL1 = new ArrayDeque<>(system.getBufferQueueSize());
    innerQueueL2 = new LinkedList<>();
    innerQueueL1 = new CircularFifoQueue<>(system.getQueueSize());

    antiFloodingEnabled = new AtomicBoolean(false);

    newMessage = new AtomicBoolean(true);
}

From source file:org.j2free.http.QueuedHttpCallService.java

/**
 * Enables this service.//from  ww  w  .  ja v a 2 s .c  o  m
 *
 * @param corePoolSize
 * @param maxPoolSize The max number of threads
 * @param threadIdle How long a thread can be idle before terminating it
 * @param connectTimeout How long to wait for a connection
 * @param socketTimeout How long to wait for an operation
 * @throws IllegalStateException if called when the service is already running
 */
public QueuedHttpCallService(int corePoolSize, int maxPoolSize, long threadIdle, int connectTimeout,
        int socketTimeout) {
    if (maxPoolSize < 0)
        maxPoolSize = Integer.MAX_VALUE;

    executor = new ThreadPoolExecutor(corePoolSize, maxPoolSize, threadIdle, TimeUnit.SECONDS,
            new PriorityBlockingQueue<Runnable>(100));

    executor.allowCoreThreadTimeOut(true); // allow the threads to timeout if unused
    executor.prestartCoreThread(); // start up just one thread

    connectionManager = new MultiThreadedHttpConnectionManager();

    // Configure the ConnectionManager
    HttpConnectionManagerParams cmParams = connectionManager.getParams();
    cmParams.setConnectionTimeout(connectTimeout * 1000);
    cmParams.setSoTimeout(socketTimeout * 1000);
    cmParams.setMaxTotalConnections(maxPoolSize);

    httpClient = new HttpClient(connectionManager);
}

From source file:backup.datanode.DataNodeBackupProcessorBase.java

public DataNodeBackupProcessorBase(Configuration conf) throws Exception {
    int backupThreads = conf.getInt(DFS_BACKUP_DATANODE_BACKUP_THREAD_COUNT_KEY,
            DFS_BACKUP_DATANODE_BACKUP_THREAD_COUNT_DEFAULT);
    int queueDepth = conf.getInt(DFS_BACKUP_DATANODE_BACKUP_QUEUE_DEPTH_KEY,
            DFS_BACKUP_DATANODE_BACKUP_QUEUE_DEPTH_DEFAULT);
    _defaultAge = conf.getLong(DFS_BACKUP_DATANODE_BACKUP_AGE_KEY, DFS_BACKUP_DATANODE_BACKUP_AGE_DEFAULT);

    _closer = Closer.create();//  w  w w  .j  a  va  2s .c  o m
    _service = _closer.register(Executors.newFixedThreadPool(backupThreads + 1));
    _backupQueue = new PriorityBlockingQueue<>(queueDepth);

    _backupQueueDepth = Metrics.METRICS.counter(QUEUE_BACKUP);
    _enqueueBackupDropMetric = Metrics.METRICS.histogram(ENQUEUE_BACKUP_DROP);
    _enqueueBackupRetryMetric = Metrics.METRICS.histogram(ENQUEUE_BACKUP_RETRY);
    _backupThroughput = Metrics.METRICS.meter(BACKUP_THROUGHPUT);

    startBackupThreads(backupThreads);
}

From source file:org.jiemamy.utils.collection.CollectionsUtil.java

/**
 * {@link PriorityBlockingQueue}?????//  w w w  .  j ava2 s.c o m
 * 
 * @param <E> {@link PriorityBlockingQueue}??
 * @param c ?????
 * @return {@link PriorityBlockingQueue}???
 * @throws IllegalArgumentException ?{@code null}???
 * @see PriorityBlockingQueue#PriorityBlockingQueue(Collection)
 */
public static <E> PriorityBlockingQueue<E> newPriorityBlockingQueue(Collection<? extends E> c) {
    Validate.notNull(c);
    return new PriorityBlockingQueue<E>(c);
}

From source file:org.jiemamy.utils.collection.CollectionsUtil.java

/**
 * {@link PriorityBlockingQueue}?????/* w  ww .  j  a v  a2 s.c o m*/
 * 
 * @param <E> {@link PriorityBlockingQueue}??
 * @param initialCapacity ?????
 * @return {@link PriorityBlockingQueue}???
 * @throws IllegalArgumentException if <tt>initialCapacity</tt> is less than 1
 * @see PriorityBlockingQueue#PriorityBlockingQueue(int)
 */
public static <E> PriorityBlockingQueue<E> newPriorityBlockingQueue(int initialCapacity) {
    return new PriorityBlockingQueue<E>(initialCapacity);
}