List of usage examples for org.springframework.scheduling.concurrent ThreadPoolTaskExecutor setMaxPoolSize
public void setMaxPoolSize(int maxPoolSize)
From source file:de.codecentric.batch.configuration.TaskExecutorConfiguration.java
@Bean public TaskExecutor taskExecutor() { ThreadPoolTaskExecutor taskExecutor = new MdcThreadPoolTaskExecutor(); taskExecutor.setCorePoolSize(env.getProperty("batch.core.pool.size", Integer.class, 5)); taskExecutor.setQueueCapacity(env.getProperty("batch.queue.capacity", Integer.class, Integer.MAX_VALUE)); taskExecutor.setMaxPoolSize(env.getProperty("batch.max.pool.size", Integer.class, Integer.MAX_VALUE)); taskExecutor.afterPropertiesSet();// w ww.j a va 2 s .co m return taskExecutor; }
From source file:com.netflix.genie.common.internal.configs.AwsAutoConfiguration.java
/** * Provide an protocol resolver which will allow resources with s3:// prefixes to be resolved by the * application {@link org.springframework.core.io.ResourceLoader} provided this bean is eventually added to the * context via the//from w ww .j a v a 2 s .co m * {@link org.springframework.context.ConfigurableApplicationContext#addProtocolResolver(ProtocolResolver)} * method. * * @param resourceLoaderProperties The {@link AwsS3ResourceLoaderProperties} instance to use * @param s3ClientFactory The {@link S3ClientFactory} instance to use * @return A {@link S3ProtocolResolver} instance */ @Bean @ConditionalOnMissingBean(S3ProtocolResolver.class) public S3ProtocolResolver s3ProtocolResolver(final AwsS3ResourceLoaderProperties resourceLoaderProperties, final S3ClientFactory s3ClientFactory) { final ThreadPoolTaskExecutor s3TaskExecutor = new ThreadPoolTaskExecutor(); s3TaskExecutor.setCorePoolSize(resourceLoaderProperties.getCorePoolSize()); s3TaskExecutor.setMaxPoolSize(resourceLoaderProperties.getMaxPoolSize()); s3TaskExecutor.setQueueCapacity(resourceLoaderProperties.getQueueCapacity()); s3TaskExecutor.setThreadGroupName("Genie-S3-Resource-Loader-Thread-Pool"); s3TaskExecutor.setThreadNamePrefix("S3-resource-loader-thread"); return new S3ProtocolResolver(s3ClientFactory, s3TaskExecutor); }
From source file:org.red5.client.net.rtmp.RTMPConnManager.java
/** * Creates a connection instance based on the supplied type. * /* w ww. j a va 2 s.c o m*/ * @param cls * @return connection * @throws Exception */ public RTMPConnection createConnectionInstance(Class<?> cls) throws Exception { RTMPConnection conn = null; if (cls == RTMPMinaConnection.class) { conn = (RTMPMinaConnection) cls.newInstance(); } else if (cls == RTMPTClientConnection.class) { conn = (RTMPTClientConnection) cls.newInstance(); } else { conn = (RTMPConnection) cls.newInstance(); } conn.setMaxHandshakeTimeout(maxHandshakeTimeout); conn.setMaxInactivity(maxInactivity); conn.setPingInterval(pingInterval); // setup executor ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); executor.setCorePoolSize(1); executor.setDaemon(true); executor.setMaxPoolSize(1); executor.setQueueCapacity(executorQueueCapacity); executor.initialize(); conn.setExecutor(executor); return conn; }
From source file:org.logger.event.web.controller.EventController.java
@Override public Executor getAsyncExecutor() { ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); executor.setCorePoolSize(15);/* w ww. j ava2 s . c o m*/ executor.setMaxPoolSize(80); executor.setQueueCapacity(200); executor.setThreadNamePrefix("eventExecutor"); executor.initialize(); return executor; }
From source file:com.ciphertool.sentencebuilder.etl.importers.WordListImporterImplTest.java
@Test public void testImportWordList() { ThreadPoolTaskExecutor taskExecutorSpy = spy(new ThreadPoolTaskExecutor()); taskExecutorSpy.setCorePoolSize(4);/*from ww w .jav a 2 s . c o m*/ taskExecutorSpy.setMaxPoolSize(4); taskExecutorSpy.setQueueCapacity(100); taskExecutorSpy.setKeepAliveSeconds(1); taskExecutorSpy.setAllowCoreThreadTimeOut(true); taskExecutorSpy.initialize(); WordListImporterImpl wordListImporterImpl = new WordListImporterImpl(); wordListImporterImpl.setTaskExecutor(taskExecutorSpy); Field rowCountField = ReflectionUtils.findField(WordListImporterImpl.class, "rowCount"); ReflectionUtils.makeAccessible(rowCountField); AtomicInteger rowCountFromObject = (AtomicInteger) ReflectionUtils.getField(rowCountField, wordListImporterImpl); assertEquals(0, rowCountFromObject.intValue()); WordDao wordDaoMock = mock(WordDao.class); when(wordDaoMock.insertBatch(anyListOf(Word.class))).thenReturn(true); int persistenceBatchSizeToSet = 3; int concurrencyBatchSizeToSet = 3; wordListImporterImpl.setWordDao(wordDaoMock); wordListImporterImpl.setPersistenceBatchSize(persistenceBatchSizeToSet); wordListImporterImpl.setConcurrencyBatchSize(concurrencyBatchSizeToSet); Word word1 = new Word(new WordId("george", PartOfSpeechType.NOUN)); Word word2 = new Word(new WordId("elmer", PartOfSpeechType.NOUN)); Word word3 = new Word(new WordId("belden", PartOfSpeechType.NOUN)); List<Word> wordsToReturn = new ArrayList<Word>(); wordsToReturn.add(word1); wordsToReturn.add(word2); wordsToReturn.add(word3); PartOfSpeechFileParser fileParserMock = mock(PartOfSpeechFileParser.class); when(fileParserMock.parseFile()).thenReturn(wordsToReturn); wordListImporterImpl.setFileParser(fileParserMock); wordListImporterImpl.importWordList(); rowCountFromObject = (AtomicInteger) ReflectionUtils.getField(rowCountField, wordListImporterImpl); assertEquals(3, rowCountFromObject.intValue()); verify(wordDaoMock, times(1)).insertBatch(anyListOf(Word.class)); verify(taskExecutorSpy, times(1)).execute(any(Runnable.class)); }
From source file:com.ciphertool.sentencebuilder.etl.importers.WordListImporterImplTest.java
@Test public void testImportWordList_LeftoversFromBatch() { ThreadPoolTaskExecutor taskExecutorSpy = spy(new ThreadPoolTaskExecutor()); taskExecutorSpy.setCorePoolSize(4);//from ww w . j a v a2 s . c om taskExecutorSpy.setMaxPoolSize(4); taskExecutorSpy.setQueueCapacity(100); taskExecutorSpy.setKeepAliveSeconds(1); taskExecutorSpy.setAllowCoreThreadTimeOut(true); taskExecutorSpy.initialize(); WordListImporterImpl wordListImporterImpl = new WordListImporterImpl(); wordListImporterImpl.setTaskExecutor(taskExecutorSpy); Field rowCountField = ReflectionUtils.findField(WordListImporterImpl.class, "rowCount"); ReflectionUtils.makeAccessible(rowCountField); AtomicInteger rowCountFromObject = (AtomicInteger) ReflectionUtils.getField(rowCountField, wordListImporterImpl); assertEquals(0, rowCountFromObject.intValue()); WordDao wordDaoMock = mock(WordDao.class); when(wordDaoMock.insertBatch(anyListOf(Word.class))).thenReturn(true); int persistenceBatchSizeToSet = 3; int concurrencyBatchSizeToSet = 2; wordListImporterImpl.setWordDao(wordDaoMock); wordListImporterImpl.setPersistenceBatchSize(persistenceBatchSizeToSet); wordListImporterImpl.setConcurrencyBatchSize(concurrencyBatchSizeToSet); Word word1 = new Word(new WordId("george", PartOfSpeechType.NOUN)); Word word2 = new Word(new WordId("elmer", PartOfSpeechType.NOUN)); Word word3 = new Word(new WordId("belden", PartOfSpeechType.NOUN)); List<Word> wordsToReturn = new ArrayList<Word>(); wordsToReturn.add(word1); wordsToReturn.add(word2); wordsToReturn.add(word3); PartOfSpeechFileParser fileParserMock = mock(PartOfSpeechFileParser.class); when(fileParserMock.parseFile()).thenReturn(wordsToReturn); wordListImporterImpl.setFileParser(fileParserMock); wordListImporterImpl.importWordList(); rowCountFromObject = (AtomicInteger) ReflectionUtils.getField(rowCountField, wordListImporterImpl); assertEquals(3, rowCountFromObject.intValue()); verify(wordDaoMock, times(2)).insertBatch(anyListOf(Word.class)); verify(taskExecutorSpy, times(2)).execute(any(Runnable.class)); }
From source file:ch.rasc.wampspring.config.DefaultWampConfiguration.java
@Bean public Executor clientInboundChannelExecutor() { ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); executor.setThreadNamePrefix("wampClientInboundChannel-"); executor.setCorePoolSize(Runtime.getRuntime().availableProcessors() * 2); executor.setMaxPoolSize(Integer.MAX_VALUE); executor.setKeepAliveSeconds(60);// w w w . j ava 2 s. c o m executor.setQueueCapacity(Integer.MAX_VALUE); executor.setAllowCoreThreadTimeOut(true); return executor; }
From source file:ch.rasc.wampspring.config.DefaultWampConfiguration.java
@Bean public Executor clientOutboundChannelExecutor() { ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); executor.setThreadNamePrefix("wampClientOutboundChannel-"); executor.setCorePoolSize(Runtime.getRuntime().availableProcessors() * 2); executor.setMaxPoolSize(Integer.MAX_VALUE); executor.setKeepAliveSeconds(60);// w w w .ja v a 2s . c o m executor.setQueueCapacity(Integer.MAX_VALUE); executor.setAllowCoreThreadTimeOut(true); return executor; }
From source file:com.ciphertool.sentencebuilder.etl.importers.FrequencyListImporterImplTest.java
@Test public void testImportFrequencyList() { ThreadPoolTaskExecutor taskExecutorSpy = spy(new ThreadPoolTaskExecutor()); taskExecutorSpy.setCorePoolSize(4);//from w w w .j a va2 s . c om taskExecutorSpy.setMaxPoolSize(4); taskExecutorSpy.setQueueCapacity(100); taskExecutorSpy.setKeepAliveSeconds(1); taskExecutorSpy.setAllowCoreThreadTimeOut(true); taskExecutorSpy.initialize(); FrequencyListImporterImpl frequencyListImporterImpl = new FrequencyListImporterImpl(); frequencyListImporterImpl.setTaskExecutor(taskExecutorSpy); Field rowUpdateCountField = ReflectionUtils.findField(FrequencyListImporterImpl.class, "rowUpdateCount"); ReflectionUtils.makeAccessible(rowUpdateCountField); AtomicInteger rowUpdateCountFromObject = (AtomicInteger) ReflectionUtils.getField(rowUpdateCountField, frequencyListImporterImpl); assertEquals(0, rowUpdateCountFromObject.intValue()); Field rowInsertCountField = ReflectionUtils.findField(FrequencyListImporterImpl.class, "rowInsertCount"); ReflectionUtils.makeAccessible(rowInsertCountField); AtomicInteger rowInsertCountFromObject = (AtomicInteger) ReflectionUtils.getField(rowInsertCountField, frequencyListImporterImpl); assertEquals(0, rowInsertCountFromObject.intValue()); WordDao wordDaoMock = mock(WordDao.class); when(wordDaoMock.insertBatch(anyListOf(Word.class))).thenReturn(true); int persistenceBatchSizeToSet = 2; int concurrencyBatchSizeToSet = 2; frequencyListImporterImpl.setWordDao(wordDaoMock); frequencyListImporterImpl.setPersistenceBatchSize(persistenceBatchSizeToSet); frequencyListImporterImpl.setConcurrencyBatchSize(concurrencyBatchSizeToSet); Word word1 = new Word(new WordId("george", PartOfSpeechType.NOUN), 100); Word word2 = new Word(new WordId("belden", PartOfSpeechType.NOUN), 200); Word word3 = new Word(new WordId("is", PartOfSpeechType.VERB_PARTICIPLE), 300); Word word4 = new Word(new WordId("awesome", PartOfSpeechType.ADJECTIVE), 400); List<Word> wordsToReturn = new ArrayList<Word>(); wordsToReturn.add(word1); wordsToReturn.add(word2); wordsToReturn.add(word3); wordsToReturn.add(word4); FrequencyFileParser fileParserMock = mock(FrequencyFileParser.class); when(fileParserMock.parseFile()).thenReturn(wordsToReturn); frequencyListImporterImpl.setFileParser(fileParserMock); Word wordFromDatabase1 = new Word(new WordId("george", PartOfSpeechType.NOUN)); Word wordFromDatabase2 = new Word(new WordId("belden", PartOfSpeechType.NOUN)); when(wordDaoMock.insertBatch(anyListOf(Word.class))).thenReturn(true); when(wordDaoMock.updateBatch(anyListOf(Word.class))).thenReturn(true); when(wordDaoMock.findByWordString(eq("george"))).thenReturn(Arrays.asList(wordFromDatabase1)); when(wordDaoMock.findByWordString(eq("belden"))).thenReturn(Arrays.asList(wordFromDatabase2)); when(wordDaoMock.findByWordString(eq("is"))).thenReturn(null); when(wordDaoMock.findByWordString(eq("awesome"))).thenReturn(null); frequencyListImporterImpl.importFrequencyList(); assertEquals(100, wordFromDatabase1.getFrequencyWeight()); assertEquals(200, wordFromDatabase2.getFrequencyWeight()); rowUpdateCountFromObject = (AtomicInteger) ReflectionUtils.getField(rowUpdateCountField, frequencyListImporterImpl); rowInsertCountFromObject = (AtomicInteger) ReflectionUtils.getField(rowInsertCountField, frequencyListImporterImpl); assertEquals(2, rowUpdateCountFromObject.intValue()); assertEquals(2, rowInsertCountFromObject.intValue()); verify(wordDaoMock, times(1)).insertBatch(anyListOf(Word.class)); verify(wordDaoMock, times(1)).updateBatch(anyListOf(Word.class)); verify(wordDaoMock, times(4)).findByWordString(anyString()); verify(taskExecutorSpy, times(2)).execute(any(Runnable.class)); }
From source file:com.ciphertool.sentencebuilder.etl.importers.FrequencyListImporterImplTest.java
@Test public void testImportFrequencyList_LeftoversFromBatch() { ThreadPoolTaskExecutor taskExecutorSpy = spy(new ThreadPoolTaskExecutor()); taskExecutorSpy.setCorePoolSize(4);/* w w w. j a va 2 s . co m*/ taskExecutorSpy.setMaxPoolSize(4); taskExecutorSpy.setQueueCapacity(100); taskExecutorSpy.setKeepAliveSeconds(1); taskExecutorSpy.setAllowCoreThreadTimeOut(true); taskExecutorSpy.initialize(); FrequencyListImporterImpl frequencyListImporterImpl = new FrequencyListImporterImpl(); frequencyListImporterImpl.setTaskExecutor(taskExecutorSpy); Field rowUpdateCountField = ReflectionUtils.findField(FrequencyListImporterImpl.class, "rowUpdateCount"); ReflectionUtils.makeAccessible(rowUpdateCountField); AtomicInteger rowUpdateCountFromObject = (AtomicInteger) ReflectionUtils.getField(rowUpdateCountField, frequencyListImporterImpl); assertEquals(0, rowUpdateCountFromObject.intValue()); Field rowInsertCountField = ReflectionUtils.findField(FrequencyListImporterImpl.class, "rowInsertCount"); ReflectionUtils.makeAccessible(rowInsertCountField); AtomicInteger rowInsertCountFromObject = (AtomicInteger) ReflectionUtils.getField(rowInsertCountField, frequencyListImporterImpl); assertEquals(0, rowInsertCountFromObject.intValue()); WordDao wordDaoMock = mock(WordDao.class); when(wordDaoMock.insertBatch(anyListOf(Word.class))).thenReturn(true); int persistenceBatchSizeToSet = 3; int concurrencyBatchSizeToSet = 2; frequencyListImporterImpl.setWordDao(wordDaoMock); frequencyListImporterImpl.setPersistenceBatchSize(persistenceBatchSizeToSet); frequencyListImporterImpl.setConcurrencyBatchSize(concurrencyBatchSizeToSet); Word word1 = new Word(new WordId("george", PartOfSpeechType.NOUN), 100); Word word2 = new Word(new WordId("belden", PartOfSpeechType.NOUN), 200); Word word3 = new Word(new WordId("is", PartOfSpeechType.VERB_PARTICIPLE), 300); Word word4 = new Word(new WordId("super", PartOfSpeechType.ADJECTIVE), 400); Word word5 = new Word(new WordId("awesome", PartOfSpeechType.ADJECTIVE), 500); List<Word> wordsToReturn = new ArrayList<Word>(); wordsToReturn.add(word1); wordsToReturn.add(word2); wordsToReturn.add(word3); wordsToReturn.add(word4); wordsToReturn.add(word5); FrequencyFileParser fileParserMock = mock(FrequencyFileParser.class); when(fileParserMock.parseFile()).thenReturn(wordsToReturn); frequencyListImporterImpl.setFileParser(fileParserMock); Word wordFromDatabase1 = new Word(new WordId("george", PartOfSpeechType.NOUN)); Word wordFromDatabase2 = new Word(new WordId("belden", PartOfSpeechType.NOUN)); Word wordFromDatabase3 = new Word(new WordId("is", PartOfSpeechType.ADJECTIVE)); when(wordDaoMock.insertBatch(anyListOf(Word.class))).thenReturn(true); when(wordDaoMock.updateBatch(anyListOf(Word.class))).thenReturn(true); when(wordDaoMock.findByWordString(eq("george"))).thenReturn(Arrays.asList(wordFromDatabase1)); when(wordDaoMock.findByWordString(eq("belden"))).thenReturn(Arrays.asList(wordFromDatabase2)); when(wordDaoMock.findByWordString(eq("is"))).thenReturn( Arrays.asList(wordFromDatabase3)); when(wordDaoMock.findByWordString(eq("super"))).thenReturn(null); when(wordDaoMock.findByWordString(eq("seriously"))).thenReturn(null); when(wordDaoMock.findByWordString(eq("awesome"))).thenReturn(null); frequencyListImporterImpl.importFrequencyList(); assertEquals(100, wordFromDatabase1.getFrequencyWeight()); assertEquals(200, wordFromDatabase2.getFrequencyWeight()); assertEquals(300, wordFromDatabase3.getFrequencyWeight()); rowUpdateCountFromObject = (AtomicInteger) ReflectionUtils.getField(rowUpdateCountField, frequencyListImporterImpl); rowInsertCountFromObject = (AtomicInteger) ReflectionUtils.getField(rowInsertCountField, frequencyListImporterImpl); assertEquals(3, rowUpdateCountFromObject.intValue()); assertEquals(2, rowInsertCountFromObject.intValue()); verify(wordDaoMock, times(2)).insertBatch(anyListOf(Word.class)); verify(wordDaoMock, times(2)).updateBatch(anyListOf(Word.class)); verify(wordDaoMock, times(5)).findByWordString(anyString()); verify(taskExecutorSpy, times(3)).execute(any(Runnable.class)); }