List of usage examples for com.google.common.util.concurrent ThreadFactoryBuilder ThreadFactoryBuilder
public ThreadFactoryBuilder()
From source file:org.jdag.common.NamedThreadFactory.java
/** * Returns a <code>ThreadFactory that creates threads with the simple * name of the class./*ww w . j a v a 2s . c om*/ */ public static ThreadFactory newNamedFactory(Class<?> hostClass) { ThreadFactoryBuilder tfBuilder = new ThreadFactoryBuilder(); ThreadFactory namedFactory = tfBuilder.setNameFormat(hostClass.getSimpleName()).build(); return namedFactory; }
From source file:com.netflix.curator.utils.ThreadUtils.java
public static ThreadFactory newThreadFactory(String processName) { return new ThreadFactoryBuilder().setNameFormat(processName + "-%d").setDaemon(true).build(); }
From source file:com.github.trask.sandbox.executors.DaemonExecutors.java
public static ExecutorService newCachedThreadPool(String name) { return Executors.newCachedThreadPool( new ThreadFactoryBuilder().setDaemon(true).setNameFormat(name + NAME_COUNTER_SUFFIX) .setUncaughtExceptionHandler(new ExceptionHandler()).build()); }
From source file:org.glowroot.central.EventLoopGroups.java
static EventLoopGroup create(String name) { ThreadFactory threadFactory = new ThreadFactoryBuilder().setDaemon(true).setNameFormat(name + "-%d") .build();/*from w w w . j a v a2s .com*/ final ExecutorService executor = Executors.newSingleThreadExecutor(threadFactory); NioEventLoopGroup nioEventLoopGroup = new NioEventLoopGroup(1, executor); nioEventLoopGroup.terminationFuture().addListener(new GenericFutureListener<Future<Object>>() { @Override public void operationComplete(Future<Object> future) throws Exception { executor.shutdown(); if (!executor.awaitTermination(10, SECONDS)) { throw new IllegalStateException("Could not terminate executor"); } } }); return nioEventLoopGroup; }
From source file:org.glowroot.agent.central.EventLoopGroups.java
static EventLoopGroup create(String name) { final ExecutorService executor = Executors .newSingleThreadExecutor(new ThreadFactoryBuilder().setDaemon(true).setNameFormat(name).build()); NioEventLoopGroup nioEventLoopGroup = new NioEventLoopGroup(1, executor); nioEventLoopGroup.terminationFuture().addListener(new GenericFutureListener<Future<Object>>() { @Override/* w ww . ja v a2 s. c o m*/ public void operationComplete(Future<Object> future) throws Exception { executor.shutdown(); if (!executor.awaitTermination(10, SECONDS)) { throw new IllegalStateException("Could not terminate executor"); } } }); return nioEventLoopGroup; }
From source file:org.glowroot.agent.it.harness.impl.EventLoopGroups.java
static EventLoopGroup create(String name) { final ExecutorService executor = Executors .newSingleThreadExecutor(new ThreadFactoryBuilder().setDaemon(true).setNameFormat(name).build()); NioEventLoopGroup nioEventLoopGroup = new NioEventLoopGroup(1, executor); nioEventLoopGroup.terminationFuture() .addListener(new GenericFutureListener<Future</*@Nullable*/ Object>>() { @Override/* ww w. ja v a 2s . co m*/ public void operationComplete(Future</*@Nullable*/ Object> future) throws Exception { executor.shutdown(); if (!executor.awaitTermination(10, SECONDS)) { throw new IllegalStateException("Could not terminate executor"); } } }); return nioEventLoopGroup; }
From source file:com.hpcloud.util.concurrent.ThreadPools.java
public static InstrumentedThreadPoolExecutor newInstrumentedCachedThreadPool(MetricRegistry metricRegistry, String name) {// w w w.j av a2 s . c o m return new InstrumentedThreadPoolExecutor(metricRegistry, name, 0, Integer.MAX_VALUE, 60l, TimeUnit.SECONDS, new SynchronousQueue<Runnable>(), new ThreadFactoryBuilder().setNameFormat(name + "-%s").build()); }
From source file:com.cinchapi.common.collect.concurrent.ThreadFactories.java
/** * Return a {@link ThreadFactory} that uses the specified {@code nameFormat} * for new threads.//w w w. j a v a 2 s .c o m * * @param nameFormat the name format for new threads * @return a {@link ThreadFactory} configured to name new threads using the * {@code nameFormat} and all other default options */ public static ThreadFactory namingThreadFactory(String nameFormat) { return new ThreadFactoryBuilder().setNameFormat(nameFormat).build(); }
From source file:flipkart.mongo.replicator.core.threadfactory.TaskThreadFactoryBuilder.java
public static ThreadFactory threadFactoryInstance(String threadNamePattern) { if (!threadFactoryPool.containsKey(threadNamePattern)) { synchronized (TaskThreadFactoryBuilder.class) { if (!threadFactoryPool.containsKey(threadNamePattern)) { ThreadFactoryBuilder threadFactoryBuilder = new ThreadFactoryBuilder() .setNameFormat(threadNamePattern); threadFactoryPool.put(threadNamePattern, threadFactoryBuilder.build()); }/*from www. j a va 2s . co m*/ } } return threadFactoryPool.get(threadNamePattern); }
From source file:com.github.ibole.microservice.rpc.core.ThreadPoolUtil.java
/** * <p>createThreadFactory.</p> * * @param namePrefix a {@link java.lang.String} object. * @return a {@link java.util.concurrent.ThreadFactory} object. *///from w w w.j a v a 2 s . co m public static ThreadFactory createThreadFactory(String namePrefix) { return new ThreadFactoryBuilder().setDaemon(true).setNameFormat(namePrefix + "-%d").build(); }