@Override public ExecutorService get() { return Executors.newFixedThreadPool(proxiedRequestsMaxThreads, new ThreadFactoryBuilder() .setNameFormat("proxied-requests-pool-%d") .setDaemon(true) .setUncaughtExceptionHandler(new Tools.LogUncaughtExceptionHandler(LoggerFactory.getLogger(ProxiedResource.class.getName()))) .build() ); } }
private static ThreadPoolExecutor createDelegate() { ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor( MAX_THREAD_COUNT, MAX_THREAD_COUNT, KEEP_ALIVE_TIME_IN_MINUTES, MINUTES, new LinkedBlockingQueue<>(UNLIMITED_QUEUE), new ThreadFactoryBuilder() .setDaemon(false) .setNameFormat("SQ_async-%d") .setUncaughtExceptionHandler(((t, e) -> LOG.error("Thread " + t + " failed unexpectedly", e))) .build()); threadPoolExecutor.allowCoreThreadTimeOut(true); return threadPoolExecutor; }
private static ThreadFactory newThreadFactory(ThreadFactoryBuilder builder, Optional<Logger> logger, Optional<String> nameFormat) { if (nameFormat.isPresent()) { builder.setNameFormat(nameFormat.get()); } return builder.setUncaughtExceptionHandler(new LoggingUncaughtExceptionHandler(logger)).build(); }
public PerformanceFixture(final int threads) { final String className = getClass().getSimpleName(); final String name = className + '-' + toHexString(hashCode()); final ThreadFactoryBuilder threadFactoryBuilder = new ThreadFactoryBuilder() .setNameFormat("loadtest-" + name + "-%d") .setUncaughtExceptionHandler(new ThreadExceptionHandler()); executor = newScheduledThreadPool(threads, threadFactoryBuilder.build()); client = new StubClient(executor); }
private ScheduledThreadPoolExecutor getMemoryAndRowLogExecutor() { ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(1, new ThreadFactoryBuilder() .setNameFormat("MemoryAndRowInfoLogger") .setDaemon(true) .setUncaughtExceptionHandler((Thread t, Throwable e) -> LOG.error(t + " throws exception: " + e)) .build(), new ThreadPoolExecutor.DiscardPolicy()); executor.setExecuteExistingDelayedTasksAfterShutdownPolicy(false); return executor; }
public ImmediateJobSpecScheduler(Optional<Logger> log) { super(log); _jobRunnablesThreadFactory = (new ThreadFactoryBuilder()) .setDaemon(false) .setNameFormat(getLog().getName() + "-thread-%d") .setUncaughtExceptionHandler(new LoggingUncaughtExceptionHandler(Optional.of(getLog()))) .build(); }
/** * Returns a thread factory that produces threads named according to the * supplied name pattern. * * @param pattern name pattern * @return thread factory */ public static ThreadFactory namedThreads(String pattern, Logger log) { return new ThreadFactoryBuilder() .setNameFormat(pattern) .setThreadFactory(new AtomixThreadFactory()) .setUncaughtExceptionHandler((t, e) -> log.error("Uncaught exception on " + t.getName(), e)) .build(); } }
@Override protected void configure() { // TODO Add instrumentation to ExecutorService and ThreadFactory final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(SCHEDULED_THREADS_POOL_SIZE, new ThreadFactoryBuilder() .setNameFormat("scheduled-%d") .setDaemon(false) .setUncaughtExceptionHandler(new Tools.LogUncaughtExceptionHandler(LOG)) .build() ); bind(ScheduledExecutorService.class).annotatedWith(Names.named("scheduler")).toInstance(scheduler); // TODO Add instrumentation to ExecutorService and ThreadFactory final ScheduledExecutorService daemonScheduler = Executors.newScheduledThreadPool(SCHEDULED_THREADS_POOL_SIZE, new ThreadFactoryBuilder() .setNameFormat("scheduled-daemon-%d") .setDaemon(true) .setUncaughtExceptionHandler(new Tools.LogUncaughtExceptionHandler(LOG)) .build() ); bind(ScheduledExecutorService.class).annotatedWith(Names.named("daemonScheduler")).toInstance(daemonScheduler); bind(Periodicals.class).toInstance(new Periodicals(scheduler, daemonScheduler)); } }
public void testUncaughtExceptionHandler_custom() { assertEquals( UNCAUGHT_EXCEPTION_HANDLER, builder .setUncaughtExceptionHandler(UNCAUGHT_EXCEPTION_HANDLER) .build() .newThread(monitoredRunnable) .getUncaughtExceptionHandler()); }
private SimpleTimer(int threadPoolSize) { executor = Executors.newScheduledThreadPool(threadPoolSize, new ThreadFactoryBuilder().setNameFormat("SimpleTimer-%d").setDaemon(true) .setUncaughtExceptionHandler(new ExceptionHandler()).build()); }
/** * Separated out for easy overriding in tests. */ @VisibleForTesting protected ExecutorService createParallelExecutor() { return Executors.newCachedThreadPool( new ThreadFactoryBuilder() .setDaemon(true) .setNameFormat("Logger channel (from parallel executor) to " + addr) .setUncaughtExceptionHandler( UncaughtExceptionHandlers.systemExit()) .build()); }
/** * Separated out for easy overriding in tests. */ @VisibleForTesting protected ExecutorService createSingleThreadExecutor() { return Executors.newSingleThreadExecutor( new ThreadFactoryBuilder() .setDaemon(true) .setNameFormat("Logger channel (from single-thread executor) to " + addr) .setUncaughtExceptionHandler( UncaughtExceptionHandlers.systemExit()) .build()); }
@Inject public ScheduledEmailService( @Named("ui.metadata.jdbc") JDBCPoolDataSource dataSource, LockService lockService, WebUserHttpService webUserHttpService, RakamUIConfig rakamUIConfig, EmailClientConfig emailConfig) { dbi = new DBI(dataSource); this.lockService = lockService; this.webUserHttpService = webUserHttpService; this.screenCaptureService = rakamUIConfig.getScreenCaptureService(); this.mailSender = emailConfig.getMailSender(); this.siteHost = emailConfig.getSiteUrl().getHost() + (emailConfig.getSiteUrl().getPort() == -1 ? "" : (":" + emailConfig.getSiteUrl().getPort())); this.scheduler = Executors.newScheduledThreadPool(1, new ThreadFactoryBuilder() .setNameFormat("scheduled-email-scheduler") .setUncaughtExceptionHandler((t, e) -> LOGGER.error(e)) .build()); executorService = MoreExecutors.listeningDecorator(new ForkJoinPool (Runtime.getRuntime().availableProcessors(), pool -> { ForkJoinWorkerThread forkJoinWorkerThread = ForkJoinPool.defaultForkJoinWorkerThreadFactory.newThread(pool); forkJoinWorkerThread.setName("scheduled-email-task-worker"); return forkJoinWorkerThread; }, null, true)); }
public PeriodicalManager() { // TODO make core pool size configurable this.executor = Executors.newScheduledThreadPool(5, new ThreadFactoryBuilder() .setDaemon(true) .setNameFormat("periodicals-%d") .setUncaughtExceptionHandler((thread, throwable) -> LOG.error("Uncaught exception in a periodical!", throwable)) .build() ); }
private ScheduledExecutorService createExecutorForSupervision() { ThreadFactory threadFactory = new ThreadFactoryBuilder() .setNameFormat("NonblockingConsumersSupervisor-%d") .setUncaughtExceptionHandler((t, e) -> logger.error("Exception from supervisor with name {}", t.getName(), e)).build(); return Executors.newSingleThreadScheduledExecutor(threadFactory); }
private ScheduledExecutorService getExecutor() { Logger logger = LoggerFactory.getLogger(ThroughputLimiterFactory.class); ThreadFactory threadFactory = new ThreadFactoryBuilder() .setNameFormat("ThroughputLimiterExecutor-%d") .setUncaughtExceptionHandler((t, e) -> logger.error("ThroughputLimiterExecutor failed {}", t.getName(), e)).build(); return newScheduledThreadPool(1, threadFactory); }
public TezLauncher() { if (namedThreadFactory == null) { namedThreadFactory = new ThreadFactoryBuilder() .setNameFormat("PigTezLauncher-%d") .setDaemon(true) .setUncaughtExceptionHandler(new JobControlThreadExceptionHandler()) .build(); } }
/** * For use by overriders to use custom thread factory. * But be extremely careful: called by constructor, so before sub-class' constructor will * have been invoked! */ protected ThreadFactory newThreadFactory(String contextid) { return new ThreadFactoryBuilder() .setNameFormat("brooklyn-execmanager-"+contextid+"-%d") .setUncaughtExceptionHandler(new UncaughtExceptionHandlerImplementation()) .build(); }
private ExecutorService getAssignmentExecutor(ConfigFactory configs) { Logger logger = LoggerFactory.getLogger(SupervisorControllerFactory.class); ThreadFactory threadFactory = new ThreadFactoryBuilder() .setNameFormat("AssignmentExecutor-%d") .setUncaughtExceptionHandler((t, e) -> logger.error("AssignmentExecutor failed {}", t.getName(), e)).build(); return newFixedThreadPool(configs.getIntProperty(CONSUMER_WORKLOAD_ASSIGNMENT_PROCESSING_THREAD_POOL_SIZE), threadFactory); }
@Inject public ConsumersExecutorService(ConfigFactory configFactory, HermesMetrics hermesMetrics) { ThreadFactory threadFactory = new ThreadFactoryBuilder() .setNameFormat("Consumer-%d") .setUncaughtExceptionHandler((t, e) -> logger.error("Exception from consumer with name {}", t.getName(), e)).build(); int poolSize = configFactory.getIntProperty(Configs.CONSUMER_THREAD_POOL_SIZE); executor = (ThreadPoolExecutor) Executors.newFixedThreadPool(poolSize, threadFactory); hermesMetrics.registerConsumersThreadGauge(() -> executor.getActiveCount()); }