ServiceWorkerPool { public void warmup(final GenericObjectPool<Worker> objectPool) throws CoreException { ExecutorService populator = Executors.newCachedThreadPool(new ManagedThreadFactory(this.getClass().getSimpleName())); try { log.trace("Warming up {} service-workers", maxThreads); final List<Future<Worker>> futures = new ArrayList<>(maxThreads); for (int i = 0; i < maxThreads; i++) { futures.add(populator.submit(new Callable<Worker>() { @Override public Worker call() throws Exception { return objectPool.borrowObject(); } })); } for (Worker w : waitFor(futures)) { objectPool.returnObject(w); } log.trace("ObjectPool contains {} (active) of {} objects", objectPool.getNumActive(), objectPool.getNumIdle()); } catch (Exception e) { throw ExceptionHelper.wrapCoreException(e); } finally { populator.shutdownNow(); } } ServiceWorkerPool(Service s, EventHandler eh, int maxThreads); GenericObjectPool<Worker> createCommonsObjectPool(); ExecutorService createExecutor(String prefix); @Deprecated static void closeQuietly(ObjectPool<?> pool); void warmup(final GenericObjectPool<Worker> objectPool);  }
@Test public void testWarmup() throws Exception { GenericObjectPool<ServiceWorkerPool.Worker> objPool = createCommonsObjectPool(); warmup(objPool); assertEquals(10, objPool.getNumIdle()); closeQuietly(objPool); }