Search in sources :

Example 16 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 17 with ThreadFactory

use of java.util.concurrent.ThreadFactory in project weave by continuuity.

the class SimpleKafkaClient method startUp.

@Override
protected void startUp() throws Exception {
    brokerCache.startAndWait();
    ThreadFactory threadFactory = Threads.createDaemonThreadFactory("kafka-client-netty-%d");
    NioClientBossPool bossPool = new NioClientBossPool(Executors.newSingleThreadExecutor(threadFactory), 1, new HashedWheelTimer(threadFactory), null);
    NioWorkerPool workerPool = new NioWorkerPool(Executors.newFixedThreadPool(4, threadFactory), 4);
    bootstrap = new ClientBootstrap(new NioClientSocketChannelFactory(bossPool, workerPool));
    bootstrap.setPipelineFactory(new KafkaChannelPipelineFactory());
    connectionPool = new ConnectionPool(bootstrap);
}
Also used : ThreadFactory(java.util.concurrent.ThreadFactory) NioClientBossPool(org.jboss.netty.channel.socket.nio.NioClientBossPool) NioWorkerPool(org.jboss.netty.channel.socket.nio.NioWorkerPool) NioClientSocketChannelFactory(org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory) ClientBootstrap(org.jboss.netty.bootstrap.ClientBootstrap) HashedWheelTimer(org.jboss.netty.util.HashedWheelTimer)

Example 18 with ThreadFactory

use of java.util.concurrent.ThreadFactory in project dropwizard by dropwizard.

the class LifecycleEnvironmentTest method executorServiceThreadFactory.

@Test
public void executorServiceThreadFactory() throws ExecutionException, InterruptedException {
    final String expectedName = "DropWizard ThreadFactory Test";
    final String expectedNamePattern = expectedName + "-%d";
    final ThreadFactory tfactory = (new ThreadFactoryBuilder()).setDaemon(false).setNameFormat(expectedNamePattern).build();
    final ExecutorService executorService = environment.executorService("Dropwizard Service", tfactory).build();
    final Future<Boolean> isFactoryInUse = executorService.submit(() -> Thread.currentThread().getName().startsWith(expectedName));
    assertThat(isFactoryInUse.get()).isTrue();
}
Also used : ThreadFactory(java.util.concurrent.ThreadFactory) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ExecutorService(java.util.concurrent.ExecutorService) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) Test(org.junit.Test)

Example 19 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 20 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)

Aggregations

ThreadFactory (java.util.concurrent.ThreadFactory)214 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)40 ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)38 ExecutorService (java.util.concurrent.ExecutorService)35 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)28 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)18 ScheduledThreadPoolExecutor (java.util.concurrent.ScheduledThreadPoolExecutor)18 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)14 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)13 LoggingThreadGroup (org.apache.geode.internal.logging.LoggingThreadGroup)12 Future (java.util.concurrent.Future)11 Test (org.junit.Test)11 AtomicLong (java.util.concurrent.atomic.AtomicLong)10 IOException (java.io.IOException)9 ArrayList (java.util.ArrayList)9 ChannelFuture (io.netty.channel.ChannelFuture)8 DefaultThreadFactory (io.netty.util.concurrent.DefaultThreadFactory)8 ExecutionException (java.util.concurrent.ExecutionException)7 ServerBootstrap (io.netty.bootstrap.ServerBootstrap)6 UdtChannel (io.netty.channel.udt.UdtChannel)6