/** * Tests whether the priority is set on newly created threads. */ @Test public void testNewThreadPriority() { 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 int priority = Thread.NORM_PRIORITY + 1; final BasicThreadFactory factory = builder.wrappedFactory(wrapped).priority( priority).build(); assertSame("Wrong thread", t, factory.newThread(r)); assertEquals("Wrong priority", priority, t.getPriority()); EasyMock.verify(wrapped, r); }
/** * 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); }
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); }
.namingPattern("Lens-server-snapshotter-Thread-%d") .daemon(true) .priority(Thread.NORM_PRIORITY) .build(); serverSnapshotScheduler = Executors.newSingleThreadScheduledExecutor(factory);
.namingPattern("Lens-server-refresh-tgt-Thread-%d") .daemon(true) .priority(Thread.NORM_PRIORITY) .build(); kerberosTgtScheduler = Executors.newSingleThreadScheduledExecutor(factory);
.namingPattern("SubscriptionTriggering-%d") .daemon(false) .priority(Thread.NORM_PRIORITY) .build(); RejectedExecutionHandler rejectedExecutionHandler = new RejectedExecutionHandler() {
private void startQueryExpirer() { ThreadFactory factory = new BasicThreadFactory.Builder() .namingPattern("QueryExpirer-%d") .daemon(true) .priority(Thread.NORM_PRIORITY) .build(); queryExpirer = Executors.newSingleThreadScheduledExecutor(factory); long expiryRunInterval = conf.getLong(QUERY_EXPIRY_INTERVAL_MILLIS, DEFAULT_QUERY_EXPIRY_INTERVAL_MILLIS); queryExpirer.scheduleWithFixedDelay(new Runnable() { @Override public void run() { try { expireQueries(); } catch (Exception e) { incrCounter(QUERY_EXPIRY_FAILURE_COUNTER); log.error("Unable to expire queries", e); } } }, expiryRunInterval, expiryRunInterval, TimeUnit.MILLISECONDS); log.info("Enabled periodic exipry of queries at {} millis interval", expiryRunInterval); }
/** * Create an asynchronous event listener which uses a thread poool to process events. * * @param poolSize size of the event processing pool * @param timeOutSeconds time out in seconds when an idle thread is destroyed * @param isDaemon if the threads used to process should be daemon threads, * if false, then implementation should call stop() * to stop the thread pool */ public AsyncEventListener(int poolSize, long timeOutSeconds, final boolean isDaemon) { eventQueue = new LinkedBlockingQueue<>(); ThreadFactory factory = new BasicThreadFactory.Builder() .namingPattern(getName()+"_AsyncThread-%d") .daemon(isDaemon) .priority(Thread.NORM_PRIORITY) .build(); // fixed pool with min and max equal to poolSize processor = new ThreadPoolExecutor(poolSize, poolSize, timeOutSeconds, TimeUnit.SECONDS, eventQueue, factory); processor.allowCoreThreadTimeOut(true); }
/** * Create an asynchronous event listener which uses a thread poool to process events. * * @param poolSize size of the event processing pool * @param timeOutSeconds time out in seconds when an idle thread is destroyed * @param isDaemon if the threads used to process should be daemon threads, * if false, then implementation should call stop() * to stop the thread pool */ public AsyncEventListener(int poolSize, long timeOutSeconds, final boolean isDaemon) { eventQueue = new LinkedBlockingQueue<>(); ThreadFactory factory = new BasicThreadFactory.Builder() .namingPattern(getName()+"_AsyncThread-%d") .daemon(isDaemon) .priority(Thread.NORM_PRIORITY) .build(); // fixed pool with min and max equal to poolSize processor = new ThreadPoolExecutor(poolSize, poolSize, timeOutSeconds, TimeUnit.SECONDS, eventQueue, factory); processor.allowCoreThreadTimeOut(true); }
@Override public synchronized void init(HiveConf hiveConf) { int numProcs = Runtime.getRuntime().availableProcessors(); ThreadFactory factory = new BasicThreadFactory.Builder() .namingPattern("Event_Service_Thread-%d") .daemon(false) .priority(Thread.NORM_PRIORITY) .build(); eventHandlerPool = Executors.newFixedThreadPool(hiveConf.getInt(LensConfConstants.EVENT_SERVICE_THREAD_POOL_SIZE, numProcs), factory); super.init(hiveConf); }
private void startQueryCancellationPool() { ThreadFactory factory = new BasicThreadFactory.Builder() .namingPattern("query-cancellation-pool-Thread-%d") .priority(Thread.NORM_PRIORITY) .build(); //Using fixed values for pool . corePoolSize = maximumPoolSize = 3 and keepAliveTime = 60 secs queryCancellationPool = new ThreadPoolExecutor(3, 3, 60, TimeUnit.SECONDS, new LinkedBlockingQueue(), factory); }
private static ThreadFactory buildThreadFactory() { return new BasicThreadFactory.Builder() .daemon(true) .priority(Thread.MIN_PRIORITY) .build(); } }
private static ThreadFactory buildThreadFactory() { return new BasicThreadFactory.Builder() .daemon(true) .priority(Thread.MIN_PRIORITY) .build(); } }
@Override public void initialize() throws InitializationException { this.jobs = new HashMap<List<String>, WikiProvisioningJob>(); // Setup jobs thread BasicThreadFactory factory = new BasicThreadFactory.Builder().namingPattern("XWiki provisioning thread").daemon(true) .priority(Thread.MIN_PRIORITY).build(); this.jobExecutor = Executors.newCachedThreadPool(factory); }
.namingPattern("SubscriptionTriggering-%d") .daemon(false) .priority(Thread.NORM_PRIORITY) .build(); RejectedExecutionHandler rejectedExecutionHandler = new RejectedExecutionHandler() {
.namingPattern("worker-" + "-%d") .daemon(false) .priority(Thread.NORM_PRIORITY) .build(); RejectedExecutionHandler rejectedExecutionHandler = new RejectedExecutionHandler() {