/** * Helper method for testing whether the daemon flag is taken into account. * * @param flag the value of the flag */ private void checkDaemonFlag(final boolean flag) { final ThreadFactory wrapped = EasyMock.createMock(ThreadFactory.class); final Runnable r = EasyMock.createMock(Runnable.class); final Thread t = new Thread(); EasyMock.expect(wrapped.newThread(r)).andReturn(t); EasyMock.replay(wrapped, r); final BasicThreadFactory factory = builder.wrappedFactory(wrapped).daemon( flag).build(); assertSame("Wrong thread", t, factory.newThread(r)); assertTrue("Wrong daemon flag", flag == t.isDaemon()); EasyMock.verify(wrapped, r); }
MetastoreStatsConnector(int cacheSize, int batchSize, StatsSource ss) { this.ss = ss; executor = Executors.newSingleThreadExecutor( new BasicThreadFactory.Builder() .namingPattern("Metastore-RuntimeStats-Loader-%d") .daemon(true) .build()); executor.submit(new RuntimeStatsLoader(cacheSize, batchSize)); }
.namingPattern( "PullMessageTask-" + messageType + "-thread-pool-%d") .daemon(true).build()); executorService = scheduledExecutorService;
@Bean(name = "scheduledExecutorService") protected ScheduledExecutorService scheduleTaskExuctor() { return new ScheduledThreadPoolExecutor(corePoolSize, new BasicThreadFactory.Builder().namingPattern("schedule-pool-%d").daemon(true).build()); }
@Bean public ScheduledExecutorService jobExecutorService() { return Executors.newScheduledThreadPool( ontrackConfigProperties.getJobs().getPoolSize(), new BasicThreadFactory.Builder() .daemon(true) .namingPattern("job-%s") .build() ); }
/** * Configures with default cached thread thread pool. */ public ThreadedListenerManager() { managerNumber = MANAGER_COUNT.getAndIncrement(); BasicThreadFactory factory = new BasicThreadFactory.Builder() .namingPattern("listenerPool" + managerNumber + "-thread%d") .daemon(true) .build(); ThreadPoolExecutor defaultPool = (ThreadPoolExecutor) Executors.newCachedThreadPool(factory); defaultPool.allowCoreThreadTimeOut(true); this.pool = defaultPool; }
public void addListener(Listener listener, boolean isBackground) { if (!isBackground) super.addListener(listener); else { BasicThreadFactory factory = new BasicThreadFactory.Builder() .namingPattern("backgroundPool" + managerNumber + "-backgroundThread" + backgroundCount.getAndIncrement() + "-%d") .daemon(true) .build(); backgroundListeners.put(listener, Executors.newSingleThreadExecutor(factory)); } }
/** * Configures with default cached thread thread pool. */ public ThreadedListenerManager() { managerNumber = MANAGER_COUNT.getAndIncrement(); BasicThreadFactory factory = new BasicThreadFactory.Builder().namingPattern("listenerPool" + managerNumber + "-thread%d").daemon(true).build(); ThreadPoolExecutor defaultPool = (ThreadPoolExecutor)Executors.newCachedThreadPool(factory); defaultPool.allowCoreThreadTimeOut(true); this.pool = defaultPool; }
private static ThreadFactory buildThreadFactory() { return new BasicThreadFactory.Builder() .daemon(true) .priority(Thread.MIN_PRIORITY) .build(); } }
/** * 生成定时线程池 * @param name 名称 * @param corePollSize 核心线程数 */ public static ScheduledExecutorService getScheduledExecutorService(String name, int corePollSize) { BasicThreadFactory basicThreadFactory = new BasicThreadFactory.Builder().namingPattern(name + "-schedule-pool-%d").daemon(true).build(); return new ScheduledThreadPoolExecutor(corePollSize, basicThreadFactory, new ThreadPoolExecutor.CallerRunsPolicy()); }
public LinkedBlockingQueueSubscribableChannel(BlockingQueue<Runnable> theQueue, String theThreadNamingPattern) { ThreadFactory threadFactory = new BasicThreadFactory.Builder() .namingPattern(theThreadNamingPattern) .daemon(false) .priority(Thread.NORM_PRIORITY) .build(); RejectedExecutionHandler rejectedExecutionHandler = (theRunnable, theExecutor) -> { ourLog.info("Note: Executor queue is full ({} elements), waiting for a slot to become available!", theQueue.size()); StopWatch sw = new StopWatch(); try { theQueue.put(theRunnable); } catch (InterruptedException theE) { throw new RejectedExecutionException("Task " + theRunnable.toString() + " rejected from " + theE.toString()); } ourLog.info("Slot become available after {}ms", sw.getMillis()); }; ThreadPoolExecutor executor = new ThreadPoolExecutor( 1, SubscriptionConstants.EXECUTOR_THREAD_COUNT, 0L, TimeUnit.MILLISECONDS, theQueue, threadFactory, rejectedExecutionHandler); myQueue = theQueue; mySubscribableChannel = new ExecutorSubscribableChannel(executor); }
BasicThreadFactory threadFactory = new BasicThreadFactory.Builder() .namingPattern("SubscriptionTriggering-%d") .daemon(false) .priority(Thread.NORM_PRIORITY) .build();
BasicThreadFactory threadFactory = new BasicThreadFactory.Builder() .namingPattern("worker-" + "-%d") .daemon(false) .priority(Thread.NORM_PRIORITY) .build();
/** * Creates a default executor service. This method is called if no executor * has been passed to the constructor. * * @return the default executor service */ private static ScheduledExecutorService createDefaultExecutorService() { final ThreadFactory factory = new BasicThreadFactory.Builder() .namingPattern("ReloadingTrigger-%s").daemon(true) .build(); return Executors.newScheduledThreadPool(1, factory); } }
.namingPattern( "PullMessageTask-" + messageType + "-thread-pool-%d") .daemon(true).build()); executorService = scheduledExecutorService;
.namingPattern( "PullMessageTask-" + messageType + "-thread-pool-%d") .daemon(true).build()); executorService = scheduledExecutorService;
@VisibleForTesting public static void scheduleClearDanglingScratchDir(HiveConf hiveConf, int initialWaitInSec) { if (hiveConf.getBoolVar(ConfVars.HIVE_SERVER2_CLEAR_DANGLING_SCRATCH_DIR)) { ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor( new BasicThreadFactory.Builder() .namingPattern("cleardanglingscratchdir-%d") .daemon(true) .build()); executor.scheduleAtFixedRate(new ClearDanglingScratchDir(false, false, false, HiveConf.getVar(hiveConf, HiveConf.ConfVars.SCRATCHDIR), hiveConf), initialWaitInSec, HiveConf.getTimeVar(hiveConf, ConfVars.HIVE_SERVER2_CLEAR_DANGLING_SCRATCH_DIR_INTERVAL, TimeUnit.SECONDS), TimeUnit.SECONDS); } }
static void scheduleCMClearer(Configuration conf) { if (MetastoreConf.getBoolVar(conf, ConfVars.REPLCMENABLED)) { ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor( new BasicThreadFactory.Builder() .namingPattern("cmclearer-%d") .daemon(true) .build()); executor.scheduleAtFixedRate(new CMClearer(MetastoreConf.getVar(conf, ConfVars.REPLCMDIR), MetastoreConf.getTimeVar(conf, ConfVars.REPLCMRETIAN, TimeUnit.SECONDS), conf), 0, MetastoreConf.getTimeVar(conf, ConfVars.REPLCMINTERVAL, TimeUnit.SECONDS), TimeUnit.SECONDS); } }
/** * Tests the reset() method of the builder. */ @Test public void testBuilderReset() { final ThreadFactory wrappedFactory = EasyMock.createMock(ThreadFactory.class); final Thread.UncaughtExceptionHandler exHandler = EasyMock .createMock(Thread.UncaughtExceptionHandler.class); EasyMock.replay(wrappedFactory, exHandler); builder.namingPattern(PATTERN).daemon(true).priority( Thread.MAX_PRIORITY).uncaughtExceptionHandler(exHandler) .wrappedFactory(wrappedFactory); builder.reset(); final BasicThreadFactory factory = builder.build(); checkFactoryDefaults(factory); assertNotSame("Wrapped factory not reset", wrappedFactory, factory .getWrappedFactory()); EasyMock.verify(wrappedFactory, exHandler); }
/** * Tests whether reset() is automatically called after build(). */ @Test public void testBuilderResetAfterBuild() { builder.wrappedFactory(EasyMock.createNiceMock(ThreadFactory.class)) .namingPattern(PATTERN).daemon(true).build(); checkFactoryDefaults(builder.build()); }