private static ThreadFactory getFactory() { return new ThreadFactoryBuilder() .setUncaughtExceptionHandler(LoggingUncaughtExceptionHandler.getInstance()) .setNameFormat(LanguageServerInitializer.class.getSimpleName()) .setDaemon(true) .build(); }
@Inject public MailSender(MailSessionProvider mailSessionProvider) { this.mailSessionProvider = mailSessionProvider; this.executor = newFixedThreadPool( 2 * Runtime.getRuntime().availableProcessors(), new ThreadFactoryBuilder() .setNameFormat("MailNotificationsPool-%d") .setDaemon(false) .setUncaughtExceptionHandler(LoggingUncaughtExceptionHandler.getInstance()) .build()); }
/** * @param corePoolSize the number of threads to keep in the pool, even if they are idle, unless * {@code allowCoreThreadTimeOut} is set */ @Inject public ThreadPullLauncher(@Named("schedule.core_pool_size") Integer corePoolSize) { this.service = new CronThreadPoolExecutor( corePoolSize, new ThreadFactoryBuilder() .setNameFormat("Annotated-scheduler-%d") .setUncaughtExceptionHandler(LoggingUncaughtExceptionHandler.getInstance()) .setDaemon(false) .build()); }
@PostConstruct private void postConstruct() { ThreadFactory factory = new ThreadFactoryBuilder() .setUncaughtExceptionHandler(LoggingUncaughtExceptionHandler.getInstance()) .setNameFormat(ServerSideRequestProcessor.class.getSimpleName() + "-%d") .setDaemon(true) .build(); executorService = new ThreadPoolExecutor( 0, maxPoolSize, 60L, TimeUnit.SECONDS, new SynchronousQueue<>(), factory); ((ThreadPoolExecutor) executorService) .setRejectedExecutionHandler( (r, executor) -> LOG.warn("Message {} rejected for execution", r)); }
/** * Stops some of the system services preparing system to full shutdown. System status is changed * from {@link SystemStatus#RUNNING} to {@link SystemStatus#PREPARING_TO_SHUTDOWN}. * * @throws ConflictException when system status is different from running */ public void stopServices() throws ConflictException { if (!statusRef.compareAndSet(RUNNING, PREPARING_TO_SHUTDOWN)) { throw new ConflictException( "System shutdown has been already called, system status: " + statusRef.get()); } ExecutorService exec = Executors.newSingleThreadExecutor( new ThreadFactoryBuilder() .setDaemon(false) .setNameFormat("ShutdownSystemServicesPool") .setUncaughtExceptionHandler(LoggingUncaughtExceptionHandler.getInstance()) .build()); exec.execute(ThreadLocalPropagateContext.wrap(this::doStopServices)); exec.shutdown(); }
/** * Suspends some of the system services preparing system to lighter shutdown. System status is * changed from {@link SystemStatus#RUNNING} to {@link SystemStatus#PREPARING_TO_SHUTDOWN}. * * @throws ConflictException when system status is different from running */ public void suspendServices() throws ConflictException { if (!statusRef.compareAndSet(RUNNING, PREPARING_TO_SHUTDOWN)) { throw new ConflictException( "System shutdown has been already called, system status: " + statusRef.get()); } ExecutorService exec = Executors.newSingleThreadExecutor( new ThreadFactoryBuilder() .setDaemon(false) .setNameFormat("SuspendSystemServicesPool") .setUncaughtExceptionHandler(LoggingUncaughtExceptionHandler.getInstance()) .build()); exec.execute(ThreadLocalPropagateContext.wrap(this::doSuspendServices)); exec.shutdown(); }
new ThreadFactoryBuilder() .setNameFormat("WorkspaceSharedPool-%d") .setUncaughtExceptionHandler(LoggingUncaughtExceptionHandler.getInstance()) .setDaemon(false) .build();
.setNameFormat("WorkspaceInitializer-%d") .setDaemon(true) .setUncaughtExceptionHandler(LoggingUncaughtExceptionHandler.getInstance()) .build());