Search in sources :

Example 1 with ThreadFactory

use of java.util.concurrent.ThreadFactory in project elasticsearch by elastic.

the class FixedExecutorBuilder method build.

@Override
ThreadPool.ExecutorHolder build(final FixedExecutorSettings settings, final ThreadContext threadContext) {
    int size = settings.size;
    int queueSize = settings.queueSize;
    final ThreadFactory threadFactory = EsExecutors.daemonThreadFactory(EsExecutors.threadName(settings.nodeName, name()));
    final ExecutorService executor = EsExecutors.newFixed(name(), size, queueSize, threadFactory, threadContext);
    final ThreadPool.Info info = new ThreadPool.Info(name(), ThreadPool.ThreadPoolType.FIXED, size, size, null, queueSize < 0 ? null : new SizeValue(queueSize));
    return new ThreadPool.ExecutorHolder(executor, info);
}
Also used : ThreadFactory(java.util.concurrent.ThreadFactory) SizeValue(org.elasticsearch.common.unit.SizeValue) ExecutorService(java.util.concurrent.ExecutorService)

Example 2 with ThreadFactory

use of java.util.concurrent.ThreadFactory in project jetty.project by eclipse.

the class ScheduledExecutorScheduler method doStart.

@Override
protected void doStart() throws Exception {
    scheduler = new ScheduledThreadPoolExecutor(1, new ThreadFactory() {

        @Override
        public Thread newThread(Runnable r) {
            Thread thread = ScheduledExecutorScheduler.this.thread = new Thread(threadGroup, r, name);
            thread.setDaemon(daemon);
            thread.setContextClassLoader(classloader);
            return thread;
        }
    });
    scheduler.setRemoveOnCancelPolicy(true);
    super.doStart();
}
Also used : ThreadFactory(java.util.concurrent.ThreadFactory) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor)

Example 3 with ThreadFactory

use of java.util.concurrent.ThreadFactory in project storm by apache.

the class Context method prepare.

/**
     * initialization per Storm configuration 
     */
@SuppressWarnings("rawtypes")
public void prepare(Map storm_conf) {
    this.storm_conf = storm_conf;
    connections = new HashMap<>();
    //each context will have a single client channel factory
    int maxWorkers = Utils.getInt(storm_conf.get(Config.STORM_MESSAGING_NETTY_CLIENT_WORKER_THREADS));
    ThreadFactory bossFactory = new NettyRenameThreadFactory("client" + "-boss");
    ThreadFactory workerFactory = new NettyRenameThreadFactory("client" + "-worker");
    if (maxWorkers > 0) {
        clientChannelFactory = new NioClientSocketChannelFactory(Executors.newCachedThreadPool(bossFactory), Executors.newCachedThreadPool(workerFactory), maxWorkers);
    } else {
        clientChannelFactory = new NioClientSocketChannelFactory(Executors.newCachedThreadPool(bossFactory), Executors.newCachedThreadPool(workerFactory));
    }
    clientScheduleService = new HashedWheelTimer(new NettyRenameThreadFactory("client-schedule-service"));
}
Also used : ThreadFactory(java.util.concurrent.ThreadFactory) NioClientSocketChannelFactory(org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory) HashedWheelTimer(org.jboss.netty.util.HashedWheelTimer)

Example 4 with ThreadFactory

use of java.util.concurrent.ThreadFactory in project hadoop by apache.

the class CleanerService method serviceInit.

@Override
protected void serviceInit(Configuration conf) throws Exception {
    this.conf = conf;
    // create scheduler executor service that services the cleaner tasks
    // use 2 threads to accommodate the on-demand tasks and reduce the chance of
    // back-to-back runs
    ThreadFactory tf = new ThreadFactoryBuilder().setNameFormat("Shared cache cleaner").build();
    scheduledExecutor = HadoopExecutors.newScheduledThreadPool(2, tf);
    super.serviceInit(conf);
}
Also used : ThreadFactory(java.util.concurrent.ThreadFactory) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder)

Example 5 with ThreadFactory

use of java.util.concurrent.ThreadFactory in project hadoop by apache.

the class InMemorySCMStore method serviceInit.

/**
   * The in-memory store bootstraps itself from the shared cache entries that
   * exist in HDFS.
   */
@Override
protected void serviceInit(Configuration conf) throws Exception {
    this.startTime = System.currentTimeMillis();
    this.initialDelayMin = getInitialDelay(conf);
    this.checkPeriodMin = getCheckPeriod(conf);
    this.stalenessMinutes = getStalenessPeriod(conf);
    bootstrap(conf);
    ThreadFactory tf = new ThreadFactoryBuilder().setNameFormat("InMemorySCMStore").build();
    scheduler = HadoopExecutors.newSingleThreadScheduledExecutor(tf);
    super.serviceInit(conf);
}
Also used : ThreadFactory(java.util.concurrent.ThreadFactory) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder)

Aggregations

ThreadFactory (java.util.concurrent.ThreadFactory)510 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)101 ExecutorService (java.util.concurrent.ExecutorService)92 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)89 ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)77 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)48 ScheduledThreadPoolExecutor (java.util.concurrent.ScheduledThreadPoolExecutor)48 Test (org.junit.Test)44 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)34 IOException (java.io.IOException)29 ArrayList (java.util.ArrayList)27 TimeUnit (java.util.concurrent.TimeUnit)25 AtomicLong (java.util.concurrent.atomic.AtomicLong)24 Future (java.util.concurrent.Future)22 CountDownLatch (java.util.concurrent.CountDownLatch)21 Executors (java.util.concurrent.Executors)19 List (java.util.List)18 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)17 ExecutionException (java.util.concurrent.ExecutionException)16 RejectedExecutionHandler (java.util.concurrent.RejectedExecutionHandler)16