@GwtIncompatible // TODO private static void useDaemonThreadFactory(ThreadPoolExecutor executor) { executor.setThreadFactory( new ThreadFactoryBuilder() .setDaemon(true) .setThreadFactory(executor.getThreadFactory()) .build()); }
@GwtIncompatible // TODO private static void useDaemonThreadFactory(ThreadPoolExecutor executor) { executor.setThreadFactory( new ThreadFactoryBuilder() .setDaemon(true) .setThreadFactory(executor.getThreadFactory()) .build()); }
/** * Returns a thread factory that produces threads named according to the * supplied name pattern. * * @param pattern name pattern * @return thread factory */ public static ThreadFactory namedThreads(String pattern, Logger log) { return new ThreadFactoryBuilder() .setNameFormat(pattern) .setThreadFactory(new AtomixThreadFactory()) .setUncaughtExceptionHandler((t, e) -> log.error("Uncaught exception on " + t.getName(), e)) .build(); } }
@GwtIncompatible // TODO private static void useDaemonThreadFactory(ThreadPoolExecutor executor) { executor.setThreadFactory( new ThreadFactoryBuilder() .setDaemon(true) .setThreadFactory(executor.getThreadFactory()) .build()); }
private OrderedScheduler(String name, int corePoolSize, ThreadFactory threadFactory, boolean traceTaskExecution, long traceTaskExecutionWarnTimeUs, StatsLogger statsLogger, StatsLogger perExecutorStatsLogger) { this.name = name; this.corePoolSize = corePoolSize; this.executors = new MonitoredScheduledThreadPoolExecutor[corePoolSize]; this.futurePools = new MonitoredFuturePool[corePoolSize]; for (int i = 0; i < corePoolSize; i++) { ThreadFactory tf = new ThreadFactoryBuilder() .setNameFormat(name + "-executor-" + i + "-%d") .setThreadFactory(threadFactory) .build(); StatsLogger broadcastStatsLogger = BroadCastStatsLogger.masterslave(perExecutorStatsLogger.scope("executor-" + i), statsLogger); executors[i] = new MonitoredScheduledThreadPoolExecutor( 1, tf, broadcastStatsLogger, traceTaskExecution); futurePools[i] = new MonitoredFuturePool( new ExecutorServiceFuturePool(executors[i]), broadcastStatsLogger.scope("futurepool"), traceTaskExecution, traceTaskExecutionWarnTimeUs); } this.random = new Random(System.currentTimeMillis()); }
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); }
/** * Builds a thread factory for the threads created by a given executor. * * <p>This is used by the default implementations in this class, and also internally to create the * Netty I/O pool. * * @param clusterName the name of the cluster, as specified by {@link * com.datastax.driver.core.Cluster.Builder#withClusterName(String)}. * @param executorName a name that identifies the executor. * @return the thread factory. */ public ThreadFactory createThreadFactory(String clusterName, String executorName) { return new ThreadFactoryBuilder() .setNameFormat(clusterName + "-" + executorName + "-%d") // Back with Netty's thread factory in order to create FastThreadLocalThread instances. This // allows // an optimization around ThreadLocals (we could use DefaultThreadFactory directly but it // creates // slightly different thread names, so keep we keep a ThreadFactoryBuilder wrapper for // backward // compatibility). .setThreadFactory(new DefaultThreadFactory("ignored name")) .build(); }
@Deprecated public ExecutorService getExecutorService() { if ( service == null ) { String name = ( getDescription() == null ) ? "unknown" : getDescription().getName(); service = Executors.newCachedThreadPool( new ThreadFactoryBuilder().setNameFormat( name + " Pool Thread #%1$d" ) .setThreadFactory( new GroupedThreadFactory( this, name ) ).build() ); } return service; } //
.setNameFormat(name + "-thread-%s") .setDaemon(true) .setThreadFactory( new ContextClassLoaderThreadFactory(JobManager.class.getClassLoader())) .build();
@Override public ThreadFactory createThreadFactory(String clusterName, String executorName) { return new ThreadFactoryBuilder() .setNameFormat(clusterName + "-" + customPrefix + "-" + executorName + "-%d") // Back with Netty's thread factory in order to create FastThreadLocalThread // instances. This allows // an optimization around ThreadLocals (we could use DefaultThreadFactory directly but // it creates // slightly different thread names, so keep we keep a ThreadFactoryBuilder wrapper for // backward // compatibility). .setThreadFactory(new DefaultThreadFactory("ignored name")) .setDaemon(true) .build(); }
.setNameFormat("QueryLogger" + "-thread-%s") .setDaemon(true) .setThreadFactory(new ThreadFactory() { @Override public Thread newThread(Runnable r) {
ThreadFactory factory = new ThreadFactoryBuilder() .setNameFormat("user thread %d") .setThreadFactory(Executors.defaultThreadFactory()) .build(); ExecutorService executorService = DynamicExecutors.newScalingThreadPool(
private static ListeningScheduledExecutorService newScheduledThreadPoolNamed(String name, int maxCount) { ThreadFactory factory = new ThreadFactoryBuilder().setNameFormat(name).setThreadFactory(defaultThreadFactory()) .build(); return listeningDecorator(maxCount == 0 ? newSingleThreadScheduledExecutor(factory) : newScheduledThreadPool( maxCount, factory)); }
private static ListeningScheduledExecutorService newScheduledThreadPoolNamed(String name, int maxCount) { ThreadFactory factory = new ThreadFactoryBuilder().setNameFormat(name).setThreadFactory(defaultThreadFactory()) .build(); return listeningDecorator(maxCount == 0 ? newSingleThreadScheduledExecutor(factory) : newScheduledThreadPool( maxCount, factory)); }
private static ExecutorService newJanitor(ThreadFactory factory) { int threadPoolSize = Runtime.getRuntime().availableProcessors(); log.info("Creating janitor executor with " + threadPoolSize + " threads"); return Executors.newFixedThreadPool( threadPoolSize, new ThreadFactoryBuilder() .setDaemon(true) .setNameFormat(JettyHttpServer.class.getName() + "-Janitor-%d") .setThreadFactory(factory) .build() ); }
public TerrainBuilder(final TerrainDataProvider terrainDataProvider, final Camera camera) { this(terrainDataProvider, camera, // PriorityExecutors.newFixedThreadPool(Runtime.getRuntime().availableProcessors(), new ThreadFactoryBuilder() // .setThreadFactory(Executors.defaultThreadFactory())// .setDaemon(true).setNameFormat("TileCacheThread-%s")// .build())); }
private static ThreadFactory newThreadFactory(final ThreadGroup threadGroup) { final ThreadFactoryBuilder builder = new ThreadFactoryBuilder(); if (threadGroup != null) { builder.setThreadFactory(new ThreadGroupAwareFactory(threadGroup)); } builder.setDaemon(true).setNameFormat("task-runner-thread-%s").setPriority(Thread.NORM_PRIORITY); return builder.build(); }
private static void useDaemonThreadFactory(ThreadPoolExecutor executor) { executor.setThreadFactory(new ThreadFactoryBuilder() .setDaemon(true) .setThreadFactory(executor.getThreadFactory()) .build()); }
private static void useDaemonThreadFactory(ThreadPoolExecutor executor) { executor.setThreadFactory(new ThreadFactoryBuilder() .setDaemon(true) .setThreadFactory(executor.getThreadFactory()) .build()); }
@GwtIncompatible("TODO") private static void useDaemonThreadFactory(ThreadPoolExecutor executor) { executor.setThreadFactory(new ThreadFactoryBuilder() .setDaemon(true) .setThreadFactory(executor.getThreadFactory()) .build()); }