ThreadPoolBuilder { public static CachedThreadPoolBuilder cachedPool() { return new CachedThreadPoolBuilder(); }  static FixedThreadPoolBuilder fixedPool(); static CachedThreadPoolBuilder cachedPool(); static ScheduledThreadPoolBuilder scheduledPool(); static QueuableCachedThreadPoolBuilder queuableCachedPool();  }
@Test public void cachedPool() { ThreadPoolExecutor singlePool = ThreadPoolBuilder.cachedPool().build(); assertThat(singlePool.getCorePoolSize()).isEqualTo(0); assertThat(singlePool.getMaximumPoolSize()).isEqualTo(Integer.MAX_VALUE); assertThat(singlePool.getKeepAliveTime(TimeUnit.SECONDS)).isEqualTo(10); assertThat(singlePool.getQueue()).isInstanceOf(SynchronousQueue.class); singlePool.shutdown(); ThreadPoolExecutor sizeablePool = ThreadPoolBuilder.cachedPool().setMinSize(10).setMaxSize(100) .setKeepAliveSecs(20).build(); assertThat(sizeablePool.getCorePoolSize()).isEqualTo(10); assertThat(sizeablePool.getMaximumPoolSize()).isEqualTo(100); assertThat(sizeablePool.getKeepAliveTime(TimeUnit.SECONDS)).isEqualTo(20); sizeablePool.shutdown(); ThreadPoolExecutor fixPoolWithNamePrefix = ThreadPoolBuilder.cachedPool().setThreadNamePrefix("cachedPool") .build(); Thread thread = fixPoolWithNamePrefix.getThreadFactory().newThread(new Runnable() { @Override public void run() { } }); assertThat(thread.getName()).startsWith("cachedPool"); fixPoolWithNamePrefix.shutdown(); }