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());
}
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());
}
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());
}
}
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);
}
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);
}
}
Aggregations