Search in sources :

Example 41 with ThreadPoolExecutor

use of java.util.concurrent.ThreadPoolExecutor in project es6draft by anba.

the class RuntimeWorkerThreadFactory method createWorkerThreadPoolExecutor.

/**
     * Returns a new {@link ThreadPoolExecutor} to create runtime worker threads.
     * 
     * @return a new {@link ThreadPoolExecutor} for runtime worker threads
     */
static ThreadPoolExecutor createWorkerThreadPoolExecutor() {
    String name = "runtimeworker-" + runtimeWorkerCount.incrementAndGet();
    ThreadPoolExecutor executor = new ThreadPoolExecutor(WORKER_THREAD_CORE_SIZE, WORKER_THREAD_POOL_SIZE, WORKER_THREAD_POOL_TTL, TimeUnit.SECONDS, new SynchronousQueue<>(), new RuntimeWorkerThreadFactory(name));
    executor.allowCoreThreadTimeOut(true);
    return executor;
}
Also used : ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor)

Example 42 with ThreadPoolExecutor

use of java.util.concurrent.ThreadPoolExecutor in project es6draft by anba.

the class RuntimeWorkerThreadFactory method createThreadPoolExecutor.

/**
     * Returns a new {@link ThreadPoolExecutor} to create runtime threads.
     * 
     * @return a new {@link ThreadPoolExecutor} for runtime threads
     */
static ThreadPoolExecutor createThreadPoolExecutor() {
    String name = "runtime-" + runtimeCount.incrementAndGet();
    ThreadPoolExecutor executor = new ThreadPoolExecutor(THREAD_POOL_SIZE, THREAD_POOL_SIZE, THREAD_POOL_TTL, TimeUnit.SECONDS, new LinkedBlockingQueue<>(), new RuntimeWorkerThreadFactory(name));
    executor.allowCoreThreadTimeOut(true);
    return executor;
}
Also used : ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor)

Example 43 with ThreadPoolExecutor

use of java.util.concurrent.ThreadPoolExecutor in project otter by alibaba.

the class DbLoadAction method adjustPoolSize.

// 调整一下线程池
private void adjustPoolSize(DbLoadContext context) {
    Pipeline pipeline = context.getPipeline();
    int newPoolSize = pipeline.getParameters().getLoadPoolSize();
    if (newPoolSize != poolSize) {
        poolSize = newPoolSize;
        if (executor instanceof ThreadPoolExecutor) {
            ThreadPoolExecutor pool = (ThreadPoolExecutor) executor;
            pool.setCorePoolSize(newPoolSize);
            pool.setMaximumPoolSize(newPoolSize);
        }
    }
}
Also used : ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) Pipeline(com.alibaba.otter.shared.common.model.config.pipeline.Pipeline)

Example 44 with ThreadPoolExecutor

use of java.util.concurrent.ThreadPoolExecutor in project otter by alibaba.

the class DatabaseExtractor method adjustPoolSize.

// 调整一下线程池
private void adjustPoolSize(int newPoolSize) {
    if (newPoolSize != poolSize) {
        poolSize = newPoolSize;
        if (executor instanceof ThreadPoolExecutor) {
            ThreadPoolExecutor pool = (ThreadPoolExecutor) executor;
            pool.setCorePoolSize(newPoolSize);
            pool.setMaximumPoolSize(newPoolSize);
        }
    }
}
Also used : ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor)

Example 45 with ThreadPoolExecutor

use of java.util.concurrent.ThreadPoolExecutor in project otter by alibaba.

the class FileLoadAction method adjustPoolSize.

private void adjustPoolSize(FileLoadContext context) {
    Pipeline pipeline = context.getPipeline();
    int newPoolSize = pipeline.getParameters().getFileLoadPoolSize();
    if (newPoolSize != poolSize) {
        poolSize = newPoolSize;
        if (executor instanceof ThreadPoolExecutor) {
            ThreadPoolExecutor pool = (ThreadPoolExecutor) executor;
            pool.setCorePoolSize(newPoolSize);
            pool.setMaximumPoolSize(newPoolSize);
        }
    }
}
Also used : ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) Pipeline(com.alibaba.otter.shared.common.model.config.pipeline.Pipeline)

Aggregations

ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)441 Test (org.junit.Test)87 ExecutorService (java.util.concurrent.ExecutorService)79 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)66 ThreadFactory (java.util.concurrent.ThreadFactory)45 SynchronousQueue (java.util.concurrent.SynchronousQueue)38 IOException (java.io.IOException)37 ArrayList (java.util.ArrayList)36 ScheduledThreadPoolExecutor (java.util.concurrent.ScheduledThreadPoolExecutor)34 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)27 RejectedExecutionHandler (java.util.concurrent.RejectedExecutionHandler)26 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)25 CountDownLatch (java.util.concurrent.CountDownLatch)25 ExecutionException (java.util.concurrent.ExecutionException)25 Future (java.util.concurrent.Future)23 ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)19 Test (org.testng.annotations.Test)18 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)17 HashMap (java.util.HashMap)16 SizedScheduledExecutorService (org.apache.camel.util.concurrent.SizedScheduledExecutorService)16