/** * 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(); } }
@Deprecated // use createClient directly public static ClientBootstrap createBootstrap(Lifecycle lifecycle) { final Timer timer = new HashedWheelTimer(new ThreadFactoryBuilder().setDaemon(true).build()); return createBootstrap(lifecycle, timer); }
/** * Get a new {@link ThreadFactory} that uses a {@link LoggingUncaughtExceptionHandler} * to handle uncaught exceptions, uses the given thread name format, and produces daemon threads. * * @param logger an {@link Optional} wrapping the {@link Logger} that the * {@link LoggingUncaughtExceptionHandler} uses to log uncaught exceptions thrown in threads * @param nameFormat an {@link Optional} wrapping a thread naming format * @return a new {@link ThreadFactory} */ public static ThreadFactory newDaemonThreadFactory(Optional<Logger> logger, Optional<String> nameFormat) { return newThreadFactory(new ThreadFactoryBuilder().setDaemon(true), logger, nameFormat); }
/** * 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(); }
@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); }
@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(); } }
@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())); } }
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())); } }
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() )); } }
TimeUnit.SECONDS, new SynchronousQueue<Runnable>(), new ThreadFactoryBuilder().setDaemon(true).build()) { @Override protected void beforeExecute(Thread t, Runnable r) {
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(); }
@SuppressWarnings("FutureReturnValueIgnored") public Stresser() { ThreadFactory threadFactory = new ThreadFactoryBuilder() .setPriority(Thread.MAX_PRIORITY) .setDaemon(true) .build(); Executors.newSingleThreadScheduledExecutor(threadFactory) .scheduleAtFixedRate(this::status, STATUS_INTERVAL, STATUS_INTERVAL, SECONDS); cache = Caffeine.newBuilder() .maximumSize(operation.maxEntries) .recordStats() .build(key -> key); local = (BoundedLocalCache<Integer, Integer>) cache.asMap(); ints = new Integer[TOTAL_KEYS]; Arrays.setAll(ints, key -> { cache.put(key, key); return key; }); cache.cleanUp(); stopwatch = Stopwatch.createStarted(); status(); }
public static ThreadFactory threadFactory(String alias) { return new ThreadFactoryBuilder() .setDaemon(true) .setNameFormat("jmxtrans-" + alias + "-%d") .build(); } }