Example usage for java.util.concurrent ThreadPoolExecutor ThreadPoolExecutor

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

Introduction

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

Prototype

public ThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit,
        BlockingQueue<Runnable> workQueue) 

Source Link

Document

Creates a new ThreadPoolExecutor with the given initial parameters, the default thread factory and the default rejected execution handler.

Usage

From source file:com.fusesource.forge.jmstest.executor.AbstractBenchmarkExecutionContainer.java

synchronized public void start(String[] args) {
    handleArguments(args);//from  w  w  w . j av  a 2 s.co m
    if (!started) {
        if (isAutoTerminate()) {
            executor = new TerminatingThreadPoolExecutor("BenchmarkExecutor", 1, 1, 10, TimeUnit.SECONDS,
                    new LinkedBlockingQueue<Runnable>());
        } else {
            executor = new ThreadPoolExecutor(1, 1, 10, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>());
        }
        executor.submit(this);
        started = true;
    }
}

From source file:com.pinterest.rocksplicator.controller.WorkerPoolTest.java

@Test
public void testAssignSameCluster() throws Exception {
    Semaphore idleWorkersSemaphore = new Semaphore(0);
    ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(1, 1, 0, TimeUnit.SECONDS,
            new ArrayBlockingQueue<Runnable>(1));
    WorkerPool workerPool = new WorkerPool(threadPoolExecutor, idleWorkersSemaphore, new TaskQueue() {
    });//from w w w  .  ja va  2  s . c  o  m
    Task task = getSleepIncrementTask();
    workerPool.assignTask(task);
    Thread.sleep(2000);
    Assert.assertEquals(1, SleepIncrementTask.executionCounter.intValue());
    workerPool.assignTask(task);
    Thread.sleep(2000);
    Assert.assertEquals(2, (int) SleepIncrementTask.executionCounter);
    Assert.assertEquals(2, idleWorkersSemaphore.availablePermits());
}

From source file:com.geecko.QuickLyric.services.BatchDownloaderService.java

public BatchDownloaderService() {
    super("Batch Downloader Service");
    mDownloadThreadPool = new ThreadPoolExecutor(CORE_POOL_SIZE, MAXIMUM_POOL_SIZE, KEEP_ALIVE_TIME,
            KEEP_ALIVE_TIME_UNIT, new LinkedBlockingQueue<Runnable>());
    this.dbHelper = DatabaseHelper.getInstance(this);
}

From source file:org.duracloud.mill.manifest.builder.ManifestBuilder.java

/**
 * // w w w .j a  va2s .  c  o  m
 * @param account
 * @param contentStores
 * @param spaceList
 * @param manifestItemRepo
 * @param clean
 * @param dryRun
 * @param threads 
 */
public void init(String account, Collection<ContentStore> contentStores, List<String> spaceList, boolean clean,
        boolean dryRun, int threads) {
    this.account = account;
    this.contentStores = contentStores;
    this.spaceList = spaceList;
    this.clean = clean;
    this.dryRun = dryRun;

    if (this.executor != null) {
        this.executor.shutdownNow();
    }

    this.successes = 0;
    this.errors = 0;
    this.totalProcessed = 0;

    this.executor = new ThreadPoolExecutor(threads, threads, 0l, TimeUnit.MILLISECONDS,
            new LinkedBlockingQueue<Runnable>(500));

}

From source file:org.geoserver.wms.WMSLifecycleHandler.java

/**
 * Shutting down pending tasks and resetting the executor service
 * timeout.// w w w.  ja v  a  2s .c  om
 */
private void resetAnimatorExecutorService() {
    shutdownAnimatorExecutorService();

    Long framesTimeout = this.wmsConfig.getMaxAnimatorRenderingTime() != null
            ? this.wmsConfig.getMaxAnimatorRenderingTime()
            : Long.MAX_VALUE;
    ExecutorService animatorExecutorService = new ThreadPoolExecutor(4, 20, framesTimeout,
            TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>());

    this.wmsConfig.setAnimatorExecutorService(animatorExecutorService);
}

From source file:org.wso2.bam.integration.tests.reciever.BAMReceiverTestCase.java

private void init() {
    threadPoolExecutor = new ThreadPoolExecutor(NUMBER_OF_THREADS, NUMBER_OF_THREADS, KEEP_ALIVE_TIME,
            TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>());
}

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

/**
 * Enables this service./*from   ww w .j  av 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:org.apache.eagle.notification.plugin.AlertEmailPlugin.java

@Override
public void init(Config config, List<AlertDefinitionAPIEntity> initAlertDefs) throws Exception {
    this.config = config;
    executorPool = new ThreadPoolExecutor(DEFAULT_THREAD_POOL_CORE_SIZE, DEFAULT_THREAD_POOL_MAX_SIZE,
            DEFAULT_THREAD_POOL_SHRINK_TIME, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>());
    LOG.info(" Creating Email Generator... ");
    for (AlertDefinitionAPIEntity entity : initAlertDefs) {
        List<Map<String, String>> configMaps = NotificationPluginUtils
                .deserializeNotificationConfig(entity.getNotificationDef());
        this.update(entity.getTags().get(Constants.POLICY_ID), configMaps, false);
    }//from  w ww . jav a  2  s.  co m
}

From source file:kr.co.bitnine.octopus.frame.SessionServer.java

@Override
protected void serviceInit(Configuration conf) throws Exception {
    super.serviceInit(conf);

    LOG.info("initialize service - " + getName());

    sessions = new ConcurrentHashMap<>();

    int sessMax = conf.getInt(OctopusConfiguration.MASTER_SESSION_MAX, EXECUTOR_MAX_DEFAULT);
    LOG.debug("create ThreadPoolExecutor for sessions (" + OctopusConfiguration.MASTER_SERVER_ADDRESS + '='
            + sessMax + ')');
    executor = new ThreadPoolExecutor(0, sessMax, EXECUTOR_KEEPALIVE_DEFAULT, TimeUnit.SECONDS,
            new SynchronousQueue<Runnable>());

    listener = new Listener();
    LOG.debug("thread " + listener.getName() + " is created");
}

From source file:org.geoserver.wps.executor.DefaultProcessManager.java

public void setMaxAsynchronousProcesses(int maxAsynchronousProcesses) {
    if (asynchService == null) {
        // create a fixed size pool. If we allow a delta between core and max 
        // the pool will create new threads only if the queue is full, but the linked queue never is
        asynchService = new ThreadPoolExecutor(maxAsynchronousProcesses, maxAsynchronousProcesses, 0L,
                TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>());
    } else {/*w w w .  j a  v a  2 s  .  c  om*/
        asynchService.setCorePoolSize(maxAsynchronousProcesses);
        asynchService.setMaximumPoolSize(maxAsynchronousProcesses);
    }
}