/** * Create a {@link ScheduledExecutorService} used ot schedule I/O and non I/O events. * * @param config the {@link AtmosphereConfig} * @return {@link ScheduledExecutorService} */ public static ScheduledExecutorService getScheduler(final AtmosphereConfig config) { final boolean shared = config.framework().isShareExecutorServices(); if (!shared || config.properties().get(SCHEDULER_THREAD_POOL) == null) { int threads = config.getInitParameter(ApplicationConfig.SCHEDULER_THREADPOOL_MAXSIZE, Runtime.getRuntime().availableProcessors()); logger.trace("Max number of Atmosphere-Scheduler {}", threads); ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(threads, new ThreadFactory() { private final AtomicInteger count = new AtomicInteger(); @Override public Thread newThread(final Runnable runnable) { Thread t = new Thread(runnable, "Atmosphere-Scheduler-" + count.getAndIncrement()); t.setDaemon(true); return t; } }); if (shared) { config.properties().put(SCHEDULER_THREAD_POOL, scheduler); } keepAliveThreads((ThreadPoolExecutor) scheduler, config); return scheduler; } else { return (ScheduledExecutorService) config.properties().get(SCHEDULER_THREAD_POOL); } }
keepAliveThreads(messageService, config);
keepAliveThreads(asyncWriteService, config);