/** * Build sharding thread factory. * * @param nameFormat thread name format * @return sharding thread factory */ public static ThreadFactory build(final String nameFormat) { return new ThreadFactoryBuilder().setDaemon(true).setNameFormat(NAME_FORMAT_PREFIX + nameFormat).build(); } }
protected static ExecutorService newSingleThreadExecutor() { return Executors.newSingleThreadExecutor(new ThreadFactoryBuilder().setNameFormat("cassandra-async-handler-%d").build()); }
@Deprecated // use createClient directly public static ClientBootstrap createBootstrap(Lifecycle lifecycle) { final Timer timer = new HashedWheelTimer(new ThreadFactoryBuilder().setDaemon(true).build()); return createBootstrap(lifecycle, timer); }
/** * Build default sharding thread factory. * * @return default sharding thread factory */ public static ThreadFactory build() { return new ThreadFactoryBuilder().setDaemon(true).setNameFormat(DEFAULT_EXECUTOR_NAME_FORMAT).build(); }
/** * 创建ThreadFactory,使得创建的线程有自己的名字而不是默认的"pool-x-thread-y" * * 使用了Guava的工具类 * * @see ThreadFactoryBuilder#build() */ public static ThreadFactory buildThreadFactory(@NotNull String threadNamePrefix) { return new ThreadFactoryBuilder().setNameFormat(threadNamePrefix + "-%d").build(); }
@GwtIncompatible // TODO private static void useDaemonThreadFactory(ThreadPoolExecutor executor) { executor.setThreadFactory( new ThreadFactoryBuilder() .setDaemon(true) .setThreadFactory(executor.getThreadFactory()) .build()); }
private ExecutorService executorService() { final ThreadFactory threadFactory = new ThreadFactoryBuilder() .setNameFormat("stream-router-%d") .setDaemon(true) .build(); return Executors.newCachedThreadPool(threadFactory); }
private ScheduledExecutorService executorService(final MetricRegistry metricRegistry) { final ThreadFactory threadFactory = new ThreadFactoryBuilder().setNameFormat("systemjob-executor-%d").build(); return new InstrumentedScheduledExecutorService( Executors.newScheduledThreadPool(THREAD_POOL_SIZE, threadFactory), metricRegistry, name(this.getClass(), "executor-service")); }
@GwtIncompatible // TODO private static void useDaemonThreadFactory(ThreadPoolExecutor executor) { executor.setThreadFactory( new ThreadFactoryBuilder() .setDaemon(true) .setThreadFactory(executor.getThreadFactory()) .build()); }
/** * Creates a {@link java.util.concurrent.ThreadFactory} that spawns off threads. * * @param nameFormat name pattern for each thread. should contain '%d' to distinguish between * threads. * @param isDaemon if true, the {@link java.util.concurrent.ThreadFactory} will create * daemon threads. * @return the created factory */ public static ThreadFactory build(final String nameFormat, boolean isDaemon) { return new ThreadFactoryBuilder().setDaemon(isDaemon).setNameFormat(nameFormat).build(); } }
private ExecutorService executorService(MetricRegistry metricRegistry) { final ThreadFactory threadFactory = new ThreadFactoryBuilder().setNameFormat("output-setup-service-%d").build(); return new InstrumentedExecutorService( Executors.newSingleThreadExecutor(threadFactory), metricRegistry, name(this.getClass(), "executor-service")); }
@GwtIncompatible // TODO private static void useDaemonThreadFactory(ThreadPoolExecutor executor) { executor.setThreadFactory( new ThreadFactoryBuilder() .setDaemon(true) .setThreadFactory(executor.getThreadFactory()) .build()); }
public CeCleaningExecutorServiceImpl() { super(Executors.newSingleThreadScheduledExecutor( new ThreadFactoryBuilder() .setDaemon(false) .setNameFormat("CE_cleaning-%d") .build())); } }
private ExecutorService executorService(final MetricRegistry metricRegistry) { final ThreadFactory threadFactory = new ThreadFactoryBuilder().setNameFormat("inputs-%d").build(); return new InstrumentedExecutorService( Executors.newCachedThreadPool(threadFactory), metricRegistry, name(this.getClass(), "executor-service")); }
public static void executeWithTimeOut(Queue<String> failures, Callable<Long> task) { ExecutorService es = Executors.newSingleThreadExecutor( new ThreadFactoryBuilder().setDaemon(true).build()); Future<Long> future = es.submit(task); try { long timeNS = future.get(TIMEOUT, TimeUnit.SECONDS); logger.debug("\nExecuted in " + TimeUnit.NANOSECONDS.toSeconds(timeNS) + " second(s)"); } catch (ExecutionException e) { fail("Exception during test: " + e.toString(), e); } catch (TimeoutException e) { handleTimout(failures, es, e); } catch (InterruptedException e) { fail("", e); } }
public HealthStateRefresherExecutorServiceImpl() { super(Executors.newSingleThreadScheduledExecutor( new ThreadFactoryBuilder() .setDaemon(false) .setNameFormat("health_state_refresh-%d") .build())); } }
private ThreadFactory threadFactory(String name, MetricRegistry metricRegistry) { final String threadFactoryMetricName = MetricRegistry.name(name, "thread-factory"); final ThreadFactory threadFactory = new ThreadFactoryBuilder().setNameFormat("netty-transport-%d").build(); return new InstrumentedThreadFactory(threadFactory, metricRegistry, threadFactoryMetricName); }
JCacheProfiler() { random = new Random(); count = new LongAdder(); CachingProvider provider = Caching.getCachingProvider(CaffeineCachingProvider.class.getName()); CacheManager cacheManager = provider.getCacheManager( provider.getDefaultURI(), provider.getDefaultClassLoader()); cache = cacheManager.createCache("profiler", new MutableConfiguration<>()); executor = Executors.newCachedThreadPool(new ThreadFactoryBuilder() .setPriority(Thread.MIN_PRIORITY).setDaemon(true).build()); }
public DatabaseMigrationExecutorServiceImpl() { super( Executors.newSingleThreadExecutor( new ThreadFactoryBuilder() .setDaemon(false) .setNameFormat("DB_migration-%d") .build() )); } }
private ExecutorService executorService(final MetricRegistry metricRegistry, final String nameFormat, final int corePoolSize, final int maxPoolSize, final int keepAliveTime) { final ThreadFactory threadFactory = new ThreadFactoryBuilder().setNameFormat(nameFormat).build(); return new InstrumentedExecutorService( new ThreadPoolExecutor(corePoolSize, maxPoolSize, keepAliveTime, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(), threadFactory), metricRegistry, name(this.getClass(), "executor-service")); }