ExecutorServiceProducer { protected ExecutorService buildFixedThreadPoolExecutorService(String key) { String stringProperty = System.getProperty(key); int threadLimit = stringProperty == null ? 0 : toInteger(stringProperty); if (threadLimit > 0) { return Executors.newFixedThreadPool(threadLimit, new DescriptiveThreadFactory()); } else { return Executors.newCachedThreadPool(new DescriptiveThreadFactory()); } } ExecutorServiceProducer(); @Produces @ApplicationScoped @Managed ExecutorService produceExecutorService(); @Produces @ApplicationScoped @Unmanaged ExecutorService produceUnmanagedExecutorService(); @Produces @ApplicationScoped @Indexing ExecutorService produceIndexingExecutorService();  }
@Test public void testSystemPropertySet() { System.setProperty(ExecutorServiceProducer.MANAGED_LIMIT_PROPERTY, "1000"); ExecutorServiceProducer producer = new ExecutorServiceProducer(); ThreadPoolExecutor executor = (ThreadPoolExecutor) producer.buildFixedThreadPoolExecutorService(ExecutorServiceProducer.MANAGED_LIMIT_PROPERTY); assertEquals(1000, executor.getMaximumPoolSize()); }
@Test public void testSystemPropertyNotSet() { System.clearProperty(ExecutorServiceProducer.MANAGED_LIMIT_PROPERTY); ExecutorServiceProducer producer = new ExecutorServiceProducer(); ThreadPoolExecutor executor = (ThreadPoolExecutor) producer.buildFixedThreadPoolExecutorService(ExecutorServiceProducer.MANAGED_LIMIT_PROPERTY); assertEquals(2147483647, executor.getMaximumPoolSize()); }