Search in sources :

Example 61 with ThreadFactory

use of java.util.concurrent.ThreadFactory in project guava by hceylan.

the class ThreadFactoryBuilderTest method testBuildMutateBuild.

public void testBuildMutateBuild() {
    ThreadFactory factory1 = builder.setPriority(1).build();
    assertEquals(1, factory1.newThread(monitoredRunnable).getPriority());
    ThreadFactory factory2 = builder.setPriority(2).build();
    assertEquals(1, factory1.newThread(monitoredRunnable).getPriority());
    assertEquals(2, factory2.newThread(monitoredRunnable).getPriority());
}
Also used : ThreadFactory(java.util.concurrent.ThreadFactory)

Example 62 with ThreadFactory

use of java.util.concurrent.ThreadFactory in project guava by hceylan.

the class ThreadFactoryBuilderTest method testDaemon_true.

public void testDaemon_true() {
    ThreadFactory factory = builder.setDaemon(true).build();
    Thread thread = factory.newThread(monitoredRunnable);
    assertTrue(thread.isDaemon());
}
Also used : ThreadFactory(java.util.concurrent.ThreadFactory)

Example 63 with ThreadFactory

use of java.util.concurrent.ThreadFactory in project guava by hceylan.

the class ThreadFactoryBuilderTest method testPriority_custom.

public void testPriority_custom() {
    for (int i = Thread.MIN_PRIORITY; i <= Thread.MAX_PRIORITY; i++) {
        ThreadFactory factory = builder.setPriority(i).build();
        Thread thread = factory.newThread(monitoredRunnable);
        assertEquals(i, thread.getPriority());
    }
}
Also used : ThreadFactory(java.util.concurrent.ThreadFactory)

Example 64 with ThreadFactory

use of java.util.concurrent.ThreadFactory in project guava by hceylan.

the class ThreadFactoryBuilderTest method testThreadFactory.

public void testThreadFactory() throws InterruptedException {
    final String THREAD_NAME = "ludicrous speed";
    final int THREAD_PRIORITY = 1;
    final boolean THREAD_DAEMON = false;
    ThreadFactory backingThreadFactory = new ThreadFactory() {

        @Override
        public Thread newThread(Runnable r) {
            Thread thread = new Thread(r);
            thread.setName(THREAD_NAME);
            thread.setPriority(THREAD_PRIORITY);
            thread.setDaemon(THREAD_DAEMON);
            thread.setUncaughtExceptionHandler(UNCAUGHT_EXCEPTION_HANDLER);
            return thread;
        }
    };
    Thread thread = builder.setThreadFactory(backingThreadFactory).build().newThread(monitoredRunnable);
    assertEquals(THREAD_NAME, thread.getName());
    assertEquals(THREAD_PRIORITY, thread.getPriority());
    assertEquals(THREAD_DAEMON, thread.isDaemon());
    assertSame(UNCAUGHT_EXCEPTION_HANDLER, thread.getUncaughtExceptionHandler());
    assertSame(Thread.State.NEW, thread.getState());
    assertFalse(completed);
    thread.start();
    thread.join();
    assertTrue(completed);
}
Also used : ThreadFactory(java.util.concurrent.ThreadFactory)

Example 65 with ThreadFactory

use of java.util.concurrent.ThreadFactory in project pulsar by yahoo.

the class PulsarClientImpl method getEventLoopGroup.

private static EventLoopGroup getEventLoopGroup(ClientConfiguration conf) {
    int numThreads = conf.getIoThreads();
    ThreadFactory threadFactory = new DefaultThreadFactory("pulsar-client-io");
    if (SystemUtils.IS_OS_LINUX) {
        try {
            return new EpollEventLoopGroup(numThreads, threadFactory);
        } catch (ExceptionInInitializerError | NoClassDefFoundError | UnsatisfiedLinkError e) {
            if (log.isDebugEnabled()) {
                log.debug("Unable to load EpollEventLoop", e);
            }
            return new NioEventLoopGroup(numThreads, threadFactory);
        }
    } else {
        return new NioEventLoopGroup(numThreads, threadFactory);
    }
}
Also used : DefaultThreadFactory(io.netty.util.concurrent.DefaultThreadFactory) DefaultThreadFactory(io.netty.util.concurrent.DefaultThreadFactory) ThreadFactory(java.util.concurrent.ThreadFactory) EpollEventLoopGroup(io.netty.channel.epoll.EpollEventLoopGroup) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup)

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