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 static ThreadFactory newThreadFactory() { return new ThreadFactoryBuilder() .setNameFormat(THREAD_NAME_PREFIX + "%d") .setPriority(Thread.MIN_PRIORITY) .build(); }
public CeProcessingSchedulerExecutorServiceImpl(CeConfiguration ceConfiguration) { super( MoreExecutors.listeningDecorator( Executors.newScheduledThreadPool(ceConfiguration.getWorkerMaxCount(), new ThreadFactoryBuilder() .setNameFormat(THREAD_NAME_PREFIX + "%d") .setPriority(Thread.MIN_PRIORITY) .build()))); }
public void testPriority_custom() { for (int i = Thread.MIN_PRIORITY; i <= Thread.MAX_PRIORITY; i++) { ThreadFactory factory = builder.setPriority(i).build(); Thread thread = factory.newThread(monitoredRunnable); assertEquals(i, thread.getPriority()); } }
/** * @param config configuration for initializing resource manager */ public ResourceManager(Configuration config) { numQueryRunnerThreads = config.getInt(QUERY_RUNNER_CONFIG_KEY, DEFAULT_QUERY_RUNNER_THREADS); numQueryWorkerThreads = config.getInt(QUERY_WORKER_CONFIG_KEY, DEFAULT_QUERY_WORKER_THREADS); LOGGER.info("Initializing with {} query runner threads and {} worker threads", numQueryRunnerThreads, numQueryWorkerThreads); // pqr -> pinot query runner (to give short names) ThreadFactory queryRunnerFactory = new ThreadFactoryBuilder().setDaemon(false).setPriority(QUERY_RUNNER_THREAD_PRIORITY).setNameFormat("pqr-%d") .build(); queryRunners = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(numQueryRunnerThreads, queryRunnerFactory)); // pqw -> pinot query workers ThreadFactory queryWorkersFactory = new ThreadFactoryBuilder().setDaemon(false).setPriority(Thread.NORM_PRIORITY).setNameFormat("pqw-%d").build(); queryWorkers = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(numQueryWorkerThreads, queryWorkersFactory)); }
public void testPriority_tooHigh() { try { builder.setPriority(Thread.MAX_PRIORITY + 1); fail(); } catch (IllegalArgumentException expected) { } }
public void testPriority_tooLow() { try { builder.setPriority(Thread.MIN_PRIORITY - 1); fail(); } catch (IllegalArgumentException expected) { } }
public void testBuildMutate() { ThreadFactory factory1 = builder.setPriority(1).build(); assertEquals(1, factory1.newThread(monitoredRunnable).getPriority()); builder.setPriority(2); // change the state of the builder assertEquals(1, factory1.newThread(monitoredRunnable).getPriority()); }
public void testBuildMutateBuild() { ThreadFactory factory1 = builder.setPriority(1).build(); assertEquals(1, factory1.newThread(monitoredRunnable).getPriority()); ThreadFactory factory2 = builder.setPriority(2).build(); assertEquals(1, factory1.newThread(monitoredRunnable).getPriority()); assertEquals(2, factory2.newThread(monitoredRunnable).getPriority()); }
.setDaemon(true) .setNameFormat("NamespaceExtractionCacheManager-%d") .setPriority(Thread.MIN_PRIORITY) .build() );
@Override public void start() { executorService = Executors.newSingleThreadScheduledExecutor( new ThreadFactoryBuilder() .setNameFormat(THREAD_NAME_PREFIX + "%d") .setPriority(Thread.MIN_PRIORITY) .build()); executorService.scheduleWithFixedDelay(() -> { try { processQueue(); } catch (Exception e) { LOG.error("Error in NotificationService", e); } }, 0, delayInSeconds, TimeUnit.SECONDS); LOG.info("Notification service started (delay {} sec.)", delayInSeconds); }
@Provides @LazySingleton public CachePopulator getCachePopulator( @Smile ObjectMapper smileMapper, CachePopulatorStats cachePopulatorStats, CacheConfig cacheConfig ) { if (cacheConfig.getNumBackgroundThreads() > 0) { final ExecutorService exec = Executors.newFixedThreadPool( cacheConfig.getNumBackgroundThreads(), new ThreadFactoryBuilder() .setNameFormat("background-cacher-%d") .setDaemon(true) .setPriority(Thread.MIN_PRIORITY) .build() ); return new BackgroundCachePopulator(exec, smileMapper, cachePopulatorStats, cacheConfig.getMaxEntrySize()); } else { return new ForegroundCachePopulator(smileMapper, cachePopulatorStats, cacheConfig.getMaxEntrySize()); } }
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()); }
@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(); }
.setDaemon(false) .setNameFormat("index-executor-%d") .setPriority(Thread.MIN_PRIORITY) .build()
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(); }
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(); }
public static ThreadPoolExecutor coreThreadsTimoutExecutor(final int numberOfThreads, final int threadPriority, final String threadNamePrefix) { final ThreadFactory factory = new ThreadFactoryBuilder().setPriority(threadPriority) .setNameFormat(threadNamePrefix + "%d").setDaemon(true).build(); final ThreadPoolExecutor pool = new ThreadPoolExecutor(numberOfThreads, numberOfThreads, 100L, MILLISECONDS, new LinkedBlockingQueue<Runnable>(), factory); pool.allowCoreThreadTimeOut(true); return pool; }
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(); }
public void testPriority_custom() { for (int i = Thread.MIN_PRIORITY; i <= Thread.MAX_PRIORITY; i++) { ThreadFactory factory = builder.setPriority(i).build(); Thread thread = factory.newThread(monitoredRunnable); assertEquals(i, thread.getPriority()); } }