DefaultExecutorFactory implements ExecutorFactory { @Override public ExecutorService createExecutorService() { int useMaxPoolSize = Math.max(corePoolSize, maxPoolSize); ThreadPoolExecutor executor = new ThreadPoolExecutor( corePoolSize, useMaxPoolSize, keepAliveTime, keepAliveTimeUnit, workQueue, threadFactory != null ? threadFactory : XpipeThreadFactory.create(threadNamePrefix), rejectedExecutionHandler); executor.allowCoreThreadTimeOut(allowCoreThreadTimeOut); return executor; } DefaultExecutorFactory(String threadNamePrefix, int corePoolSize, int maxPoolSize);  DefaultExecutorFactory(String threadNamePrefix, int corePoolSize, int maxPoolSize, RejectedExecutionHandler rejectedExecutionHandler);  DefaultExecutorFactory(String threadNamePrefix, int corePoolSize, boolean allowCoreThreadTimeOut);  DefaultExecutorFactory(String threadNamePrefix, int corePoolSize, boolean allowCoreThreadTimeOut,
                                  int maxPoolSize,
                                  int maxQueueSize, int keepAliveTime, TimeUnit keepAliveTimeUnit, RejectedExecutionHandler rejectedExecutionHandler); static DefaultExecutorFactory createAllowCoreTimeout(String threadNamePrefix); static DefaultExecutorFactory createAllowCoreTimeout(String threadNamePrefix, int corePoolSize); static DefaultExecutorFactory createAllowCoreTimeout(String threadNamePrefix, int corePoolSize, int keepAliveTimeSeconds); static DefaultExecutorFactory createAllowCoreTimeoutAbortPolicy(String threadNamePrefix); static DefaultExecutorFactory createAllowCoreTimeoutAbortPolicy(String threadNamePrefix, int corePoolSize); static DefaultExecutorFactory createAllowCoreTimeoutAbortPolicy(String threadNamePrefix, int corePoolSize, int keepAliveTimeSeconds); @Override ExecutorService createExecutorService();  }
@Test public void testArgument(){ int maxPoolSize = randomInt(100, 1000); int maxQueueSize = randomInt(100, 1000); int keeperAliveTime = randomInt(30, 60); RejectedExecutionHandler rejectedExecutionHandler = new ThreadPoolExecutor.AbortPolicy(); DefaultExecutorFactory executorFactory = new DefaultExecutorFactory(getTestName(), 2, true, maxPoolSize, maxQueueSize, keeperAliveTime, TimeUnit.SECONDS, rejectedExecutionHandler); ThreadPoolExecutor threadPoolExecutor = (ThreadPoolExecutor) executorFactory.createExecutorService(); Assert.assertEquals(2, threadPoolExecutor.getCorePoolSize()); Assert.assertEquals(maxPoolSize, threadPoolExecutor.getMaximumPoolSize()); Assert.assertEquals(maxQueueSize, threadPoolExecutor.getQueue().remainingCapacity()); Assert.assertEquals(keeperAliveTime, threadPoolExecutor.getKeepAliveTime(TimeUnit.SECONDS)); Assert.assertEquals(rejectedExecutionHandler, threadPoolExecutor.getRejectedExecutionHandler()); }
@Test public void testCoreLessThanMax(){ DefaultExecutorFactory executorFactory = new DefaultExecutorFactory(getTestName(), 2, 1); ThreadPoolExecutor threadPoolExecutor = (ThreadPoolExecutor) executorFactory.createExecutorService(); Assert.assertEquals(2, threadPoolExecutor.getCorePoolSize()); Assert.assertEquals(2, threadPoolExecutor.getMaximumPoolSize()); }