use of java.util.concurrent.ThreadFactory in project torodb by torodb.
the class StampedeBootstrap method createStampedeService.
public static Service createStampedeService(BootstrapModule bootstrapModule) {
Injector bootstrapInjector = Guice.createInjector(bootstrapModule);
ThreadFactory threadFactory = bootstrapInjector.getInstance(ThreadFactory.class);
return new StampedeService(threadFactory, bootstrapInjector);
}
use of java.util.concurrent.ThreadFactory in project jstorm by alibaba.
the class NettyContext method prepare.
/**
* initialization per Storm configuration
*/
@SuppressWarnings("rawtypes")
public void prepare(Map storm_conf) {
this.storm_conf = storm_conf;
int maxWorkers = Utils.getInt(storm_conf.get(Config.STORM_MESSAGING_NETTY_CLIENT_WORKER_THREADS));
ThreadFactory bossFactory = new NettyRenameThreadFactory(MetricDef.NETTY_CLI + "boss");
ThreadFactory workerFactory = new NettyRenameThreadFactory(MetricDef.NETTY_CLI + "worker");
if (maxWorkers > 0) {
clientChannelFactory = new NioClientSocketChannelFactory(Executors.newCachedThreadPool(bossFactory), Executors.newCachedThreadPool(workerFactory), maxWorkers);
} else {
clientChannelFactory = new NioClientSocketChannelFactory(Executors.newCachedThreadPool(bossFactory), Executors.newCachedThreadPool(workerFactory));
}
reconnector = new ReconnectRunnable();
new AsyncLoopThread(reconnector, true, Thread.MIN_PRIORITY, true);
}
use of java.util.concurrent.ThreadFactory in project guava by hceylan.
the class ThreadFactoryBuilder method build.
private static ThreadFactory build(ThreadFactoryBuilder builder) {
final String nameFormat = builder.nameFormat;
final Boolean daemon = builder.daemon;
final Integer priority = builder.priority;
final UncaughtExceptionHandler uncaughtExceptionHandler = builder.uncaughtExceptionHandler;
final ThreadFactory backingThreadFactory = (builder.backingThreadFactory != null) ? builder.backingThreadFactory : Executors.defaultThreadFactory();
final AtomicLong count = (nameFormat != null) ? new AtomicLong(0) : null;
return new ThreadFactory() {
@Override
public Thread newThread(Runnable runnable) {
Thread thread = backingThreadFactory.newThread(runnable);
if (nameFormat != null) {
thread.setName(String.format(nameFormat, count.getAndIncrement()));
}
if (daemon != null) {
thread.setDaemon(daemon);
}
if (priority != null) {
thread.setPriority(priority);
}
if (uncaughtExceptionHandler != null) {
thread.setUncaughtExceptionHandler(uncaughtExceptionHandler);
}
return thread;
}
};
}
use of java.util.concurrent.ThreadFactory in project guava by hceylan.
the class ThreadFactoryBuilderTest method testBuildMutate.
public void testBuildMutate() {
ThreadFactory factory1 = builder.setPriority(1).build();
assertEquals(1, factory1.newThread(monitoredRunnable).getPriority());
// change the state of the builder
builder.setPriority(2);
assertEquals(1, factory1.newThread(monitoredRunnable).getPriority());
}
use of java.util.concurrent.ThreadFactory in project guava by hceylan.
the class ThreadFactoryBuilderTest method testThreadFactoryBuilder_defaults.
public void testThreadFactoryBuilder_defaults() throws InterruptedException {
ThreadFactory threadFactory = builder.build();
Thread thread = threadFactory.newThread(monitoredRunnable);
checkThreadPoolName(thread, 1);
Thread defaultThread = Executors.defaultThreadFactory().newThread(monitoredRunnable);
assertEquals(defaultThread.isDaemon(), thread.isDaemon());
assertEquals(defaultThread.getPriority(), thread.getPriority());
assertSame(defaultThread.getThreadGroup(), thread.getThreadGroup());
assertSame(defaultThread.getUncaughtExceptionHandler(), thread.getUncaughtExceptionHandler());
assertFalse(completed);
thread.start();
thread.join();
assertTrue(completed);
// Creating a new thread from the same ThreadFactory will have the same
// pool ID but a thread ID of 2.
Thread thread2 = threadFactory.newThread(monitoredRunnable);
checkThreadPoolName(thread2, 2);
assertEquals(thread.getName().substring(0, thread.getName().lastIndexOf('-')), thread2.getName().substring(0, thread.getName().lastIndexOf('-')));
// Building again should give us a different pool ID.
ThreadFactory threadFactory2 = builder.build();
Thread thread3 = threadFactory2.newThread(monitoredRunnable);
checkThreadPoolName(thread3, 1);
ASSERT.that(thread2.getName().substring(0, thread.getName().lastIndexOf('-'))).isNotEqualTo(thread3.getName().substring(0, thread.getName().lastIndexOf('-')));
}
Aggregations