Java ThreadPoolExecutor getBlockingWorkExecutor()

Here you can find the source of getBlockingWorkExecutor()

Description

Get Executor for long term and potentially blocking operations.

License

Open Source License

Return

executor for blocking operations

Declaration

public static synchronized Executor getBlockingWorkExecutor() 

Method Source Code

//package com.java2s;
/* ========================================================================
 * Copyright (c) 2005-2010 The OPC Foundation, Inc. All rights reserved.
 *
 * OPC Reciprocal Community License ("RCL") Version 1.00
 * // w w w.  j a  v a 2s  .com
 * Unless explicitly acquired and licensed from Licensor under another 
 * license, the contents of this file are subject to the Reciprocal 
 * Community License ("RCL") Version 1.00, or subsequent versions as 
 * allowed by the RCL, and You may not copy or use this file in either 
 * source code or executable form, except in compliance with the terms and 
 * conditions of the RCL.
 * 
 * All software distributed under the RCL is provided strictly on an 
 * "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, 
 * AND LICENSOR HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT 
 * LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 
 * PURPOSE, QUIET ENJOYMENT, OR NON-INFRINGEMENT. See the RCL for specific 
 * language governing rights and limitations under the RCL.
 *
 * The complete license agreement can be found here:
 * http://opcfoundation.org/License/RCL/1.00/
 * ======================================================================*/

import java.util.concurrent.Executor;

import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

public class Main {
    public static Executor BLOCKING_EXECUTOR;

    /**
     * Get Executor for long term and potentially blocking operations.
     * 
     * @return executor for blocking operations
     */
    public static synchronized Executor getBlockingWorkExecutor() {
        if (BLOCKING_EXECUTOR == null) {
            final ThreadGroup tg = new ThreadGroup("Blocking-Work-Executor-Group");
            final AtomicInteger counter = new AtomicInteger(0);
            ThreadFactory tf = new ThreadFactory() {
                @Override
                public Thread newThread(Runnable r) {
                    Thread t = new Thread(tg, r, "Blocking-Work-Executor-" + (counter.incrementAndGet()));
                    t.setDaemon(true);
                    return t;
                }
            };
            BLOCKING_EXECUTOR = new ThreadPoolExecutor(0, Integer.MAX_VALUE, 3L, TimeUnit.SECONDS,
                    new SynchronousQueue<Runnable>(), tf);
        }
        return BLOCKING_EXECUTOR;
    }
}

Related

  1. createQueue(final int queueCapacity)
  2. createScheduledThreadPoolExecutor(final int poolSz, final String threadName)
  3. createThreadPoolExecutor(final int queueSize, final String threadName)
  4. executeInBackground(Runnable r)
  5. executeInDaemon(Runnable... run)
  6. getBoundedThreadPoolExecutor(int maxPoolSize, long keepAliveTime, TimeUnit unit, ThreadFactory tFactory)
  7. getScheduler()
  8. getThreadPoolExecutor(int poolSize, int[] poolInfo)
  9. getThreadPoolTrace(ThreadPoolExecutor threadpool)