ThreadPoolManager { public static ScheduledExecutorService getScheduledPool(String poolName) { ExecutorService pool = pools.get(poolName); if (pool == null) { synchronized (pools) { pool = pools.get(poolName); if (pool == null) { int cfg = getConfig(poolName); pool = new WrappedScheduledExecutorService(cfg, new NamedThreadFactory(poolName, true, Thread.NORM_PRIORITY)); ((ThreadPoolExecutor) pool).setKeepAliveTime(THREAD_TIMEOUT, TimeUnit.SECONDS); ((ThreadPoolExecutor) pool).allowCoreThreadTimeOut(true); ((ScheduledThreadPoolExecutor) pool).setRemoveOnCancelPolicy(true); pools.put(poolName, pool); LOGGER.debug("Created scheduled thread pool '{}' of size {}", poolName, cfg); } } } if (pool instanceof ScheduledExecutorService) { return (ScheduledExecutorService) pool; } else { throw new IllegalArgumentException("Pool " + poolName + " is not a scheduled pool!"); } }  static ScheduledExecutorService getScheduledPool(String poolName); static ExecutorService getPool(String poolName); static final String CONFIGURATION_PID; static final String THREAD_POOL_NAME_COMMON; }
@Test public void testGetScheduledPool() { ThreadPoolExecutor result = (ThreadPoolExecutor) ThreadPoolManager.getScheduledPool("test1"); assertThat(result, instanceOf(ScheduledExecutorService.class)); assertTrue(result.allowsCoreThreadTimeOut()); assertEquals(ThreadPoolManager.THREAD_TIMEOUT, result.getKeepAliveTime(TimeUnit.SECONDS)); assertEquals(ThreadPoolManager.DEFAULT_THREAD_POOL_SIZE, result.getCorePoolSize()); }