/** * 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()); }
public void testNameFormatWithPercentS_custom() { String format = "super-duper-thread-%s"; ThreadFactory factory = builder.setNameFormat(format).build(); for (int i = 0; i < 11; i++) { assertEquals(rootLocaleFormat(format, i), factory.newThread(monitoredRunnable).getName()); } }
/** * 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(); }
public void testNameFormatWithPercentD_custom() { String format = "super-duper-thread-%d"; ThreadFactory factory = builder.setNameFormat(format).build(); for (int i = 0; i < 11; i++) { assertEquals(rootLocaleFormat(format, i), factory.newThread(monitoredRunnable).getName()); } }
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")); }
/** * 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")); }
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 HealthStateRefresherExecutorServiceImpl() { super(Executors.newSingleThreadScheduledExecutor( new ThreadFactoryBuilder() .setDaemon(false) .setNameFormat("health_state_refresh-%d") .build())); } }
private ThreadFactory threadFactory(MetricRegistry metricRegistry) { final ThreadFactory threadFactory = new ThreadFactoryBuilder().setNameFormat("processbufferprocessor-%d").build(); return new InstrumentedThreadFactory( threadFactory, metricRegistry, name(this.getClass(), "thread-factory")); }
public DatabaseMigrationExecutorServiceImpl() { super( Executors.newSingleThreadExecutor( new ThreadFactoryBuilder() .setDaemon(false) .setNameFormat("DB_migration-%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); }
public static ThreadFactory makeThreadFactory(@NotNull String nameFormat, @Nullable Integer priority) { final ThreadFactoryBuilder builder = new ThreadFactoryBuilder() .setDaemon(true) .setNameFormat(nameFormat); if (priority != null) { builder.setPriority(priority); } return builder.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")); }
DirWatcher(AttemptRegistrationListener listener) throws IOException { this.watchService = FileSystems.getDefault().newWatchService(); this.listener = listener; ExecutorService executor1 = Executors.newFixedThreadPool(1, new ThreadFactoryBuilder().setDaemon(true).setNameFormat("DirWatcher").build()); watcherExecutorService = MoreExecutors.listeningDecorator(executor1); ExecutorService executor2 = Executors.newFixedThreadPool(1, new ThreadFactoryBuilder().setDaemon(true).setNameFormat("WatchExpirer").build()); expirerExecutorService = MoreExecutors.listeningDecorator(executor2); }
private ExecutorService executorService(MetricRegistry metricRegistry) { final ThreadFactory threadFactory = new ThreadFactoryBuilder().setNameFormat("buffer-synchronizer-%d").build(); return new InstrumentedExecutorService( Executors.newSingleThreadExecutor(threadFactory), metricRegistry, name(this.getClass(), "executor-service")); } }