ExecutorServiceBuilder { public ExecutorService build() { final ThreadPoolExecutor executor = new ThreadPoolExecutor( corePoolSize, maxPoolSize, keepAliveTime.toMillis(), TimeUnit.MILLISECONDS, workQueue, threadFactory, handler); executor.allowCoreThreadTimeOut(allowCoreThreadTimeOut); return executor; } ExecutorServiceBuilder(); ExecutorServiceBuilder corePoolSize(int corePoolSize); ExecutorServiceBuilder maxPoolSize(int maxPoolSize); ExecutorServiceBuilder allowCoreThreadTimeOut(boolean allowCoreThreadTimeOut); ExecutorServiceBuilder keepAliveTime(Duration time); ExecutorServiceBuilder workQueue(BlockingQueue<Runnable> workQueue); ExecutorServiceBuilder queueCapacity(int queueCapacity); ExecutorServiceBuilder rejectedExecutionHandler(RejectedExecutionHandler handler); ExecutorServiceBuilder threadFactory(ThreadFactory threadFactory); ExecutorService build();  }
@Test public void testBuild() { ExecutorService executorService = new ExecutorServiceBuilder() .corePoolSize(6) .maxPoolSize(12) .queueCapacity(5000) .threadFactory(threadFactory) .build(); assertTrue(executorService instanceof ThreadPoolExecutor); ThreadPoolExecutor threadPoolExecutorService = (ThreadPoolExecutor) executorService; assertEquals(threadPoolExecutorService.getCorePoolSize(), 6); assertEquals(threadPoolExecutorService.getMaximumPoolSize(), 12); assertEquals(threadPoolExecutorService.getThreadFactory(), threadFactory); }