ThreadPoolBuilder { public static FixedThreadPoolBuilder fixedPool() { return new FixedThreadPoolBuilder(); }  static FixedThreadPoolBuilder fixedPool(); static CachedThreadPoolBuilder cachedPool(); static ScheduledThreadPoolBuilder scheduledPool(); static QueuableCachedThreadPoolBuilder queuableCachedPool();  }
@Test public void fixPool() { ThreadPoolExecutor singlePool = ThreadPoolBuilder.fixedPool().build(); assertThat(singlePool.getCorePoolSize()).isEqualTo(1); assertThat(singlePool.getMaximumPoolSize()).isEqualTo(1); assertThat(singlePool.getQueue()).isInstanceOf(LinkedBlockingQueue.class); singlePool.shutdown(); ThreadPoolExecutor fixPoolWithUnlimitQueue = ThreadPoolBuilder.fixedPool().setPoolSize(10).build(); assertThat(fixPoolWithUnlimitQueue.getCorePoolSize()).isEqualTo(10); assertThat(fixPoolWithUnlimitQueue.getMaximumPoolSize()).isEqualTo(10); fixPoolWithUnlimitQueue.shutdown(); ThreadPoolExecutor fixPoolWithlimitQueue = ThreadPoolBuilder.fixedPool().setPoolSize(10).setQueueSize(100) .setThreadFactory(ThreadPoolUtil.buildThreadFactory("kaka")).build(); assertThat(fixPoolWithlimitQueue.getQueue()).isInstanceOf(ArrayBlockingQueue.class); Thread thread = fixPoolWithlimitQueue.getThreadFactory().newThread(new Runnable() { @Override public void run() { } }); assertThat(thread.getName()).startsWith("kaka"); fixPoolWithlimitQueue.shutdown(); ThreadPoolExecutor fixPoolWithNamePrefix = ThreadPoolBuilder.fixedPool().setPoolSize(10) .setThreadNamePrefix("fixPool").build(); Thread thread2 = fixPoolWithNamePrefix.getThreadFactory().newThread(new Runnable() { @Override public void run() { } }); assertThat(thread2.getName()).startsWith("fixPool"); assertThat(thread2.isDaemon()).isFalse(); fixPoolWithNamePrefix.shutdown(); ThreadPoolExecutor fixPoolWithNamePrefixAndDaemon = ThreadPoolBuilder.fixedPool().setPoolSize(10) .setThreadNamePrefix("fixPoolDaemon").setDaemon(true).build(); Thread thread3 = fixPoolWithNamePrefixAndDaemon.getThreadFactory().newThread(new Runnable() { @Override public void run() { } }); assertThat(thread3.getName()).startsWith("fixPoolDaemon"); assertThat(thread3.isDaemon()).isTrue(); fixPoolWithNamePrefixAndDaemon.shutdown(); }