ThreadPoolManager { public static ExecutorService getPool(String poolName) { ExecutorService pool = pools.get(poolName); if (pool == null) { synchronized (pools) { pool = pools.get(poolName); if (pool == null) { int cfg = getConfig(poolName); pool = QueueingThreadPoolExecutor.createInstance(poolName, cfg); ((ThreadPoolExecutor) pool).setKeepAliveTime(THREAD_TIMEOUT, TimeUnit.SECONDS); ((ThreadPoolExecutor) pool).allowCoreThreadTimeOut(true); pools.put(poolName, pool); LOGGER.debug("Created thread pool '{}' with size {}", poolName, cfg); } } } return 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 testGetCachedPool() { ExecutorService result = ThreadPoolManager.getPool("test2"); assertThat(result, instanceOf(ExecutorService.class)); ThreadPoolExecutor tpe = (ThreadPoolExecutor) result; assertTrue(tpe.allowsCoreThreadTimeOut()); assertEquals(ThreadPoolManager.THREAD_TIMEOUT, tpe.getKeepAliveTime(TimeUnit.SECONDS)); assertEquals(ThreadPoolManager.DEFAULT_THREAD_POOL_SIZE, tpe.getMaximumPoolSize()); }