List of usage examples for org.springframework.scheduling.concurrent ThreadPoolTaskExecutor setQueueCapacity
public void setQueueCapacity(int queueCapacity)
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);//from www . ja v a2s . c om 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. j a v a2 s . 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 av a 2 s .com 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);//ww w . j a v a2 s .c o 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)); }
From source file:org.finra.herd.service.config.ServiceSpringModuleConfig.java
/** * Activiti's dedicated TaskExecutor bean definition. * * @return TaskExecutor//from w w w . ja v a2 s . c om */ @Bean public TaskExecutor activitiTaskExecutor() { ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor(); taskExecutor.setCorePoolSize(configurationHelper .getProperty(ConfigurationValue.ACTIVITI_THREAD_POOL_CORE_POOL_SIZE, Integer.class)); taskExecutor.setMaxPoolSize(configurationHelper .getProperty(ConfigurationValue.ACTIVITI_THREAD_POOL_MAX_POOL_SIZE, Integer.class)); taskExecutor.setKeepAliveSeconds(configurationHelper .getProperty(ConfigurationValue.ACTIVITI_THREAD_POOL_KEEP_ALIVE_SECS, Integer.class)); taskExecutor.setQueueCapacity(configurationHelper .getProperty(ConfigurationValue.ACTIVITI_THREAD_POOL_QUEUE_CAPACITY, Integer.class)); return taskExecutor; }
From source file:org.flockdata.helper.ExecutorHelper.java
public static Executor getExecutor(String name, String poolSize, int qCapacity) { ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); String vals[] = StringUtils.split(poolSize, "-"); executor.setCorePoolSize(Integer.parseInt(vals[0])); if (vals.length == 2) executor.setMaxPoolSize(Integer.parseInt(vals[1])); else//from w ww . j av a 2 s. c om executor.setMaxPoolSize(Integer.parseInt(vals[0])); executor.setQueueCapacity(qCapacity); executor.setThreadNamePrefix(name + "-"); executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy()); executor.initialize(); return executor.getThreadPoolExecutor(); }
From source file:org.springframework.batch.core.test.step.FaultTolerantStepFactoryBeanIntegrationTests.java
@Before public void setUp() throws Exception { writer = new SkipWriterStub(dataSource); processor = new SkipProcessorStub(dataSource); factory = new FaultTolerantStepFactoryBean<String, String>(); factory.setBeanName("stepName"); factory.setTransactionManager(transactionManager); factory.setJobRepository(repository); factory.setCommitInterval(3);/*from w w w .ja v a 2 s . com*/ ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor(); taskExecutor.setCorePoolSize(3); taskExecutor.setMaxPoolSize(6); taskExecutor.setQueueCapacity(0); taskExecutor.afterPropertiesSet(); factory.setTaskExecutor(taskExecutor); JdbcTestUtils.deleteFromTables(new JdbcTemplate(dataSource), "ERROR_LOG"); }
From source file:org.springframework.batch.core.test.step.FaultTolerantStepFactoryBeanRollbackIntegrationTests.java
@Test public void testMultithreadedSkipInWriter() throws Throwable { ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor(); taskExecutor.setCorePoolSize(3);// w w w .j av a 2s . c o m taskExecutor.setMaxPoolSize(6); taskExecutor.setQueueCapacity(0); taskExecutor.afterPropertiesSet(); factory.setTaskExecutor(taskExecutor); @SuppressWarnings("unchecked") Map<Class<? extends Throwable>, Boolean> skippable = getExceptionMap(Exception.class); factory.setSkippableExceptionClasses(skippable); jobExecution = repository.createJobExecution("skipJob", new JobParameters()); for (int i = 0; i < MAX_COUNT; i++) { if (i % 100 == 0) { logger.info("Starting step: " + i); } JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); assertEquals(0, JdbcTestUtils.countRowsInTable(jdbcTemplate, "ERROR_LOG")); try { SkipReaderStub reader = new SkipReaderStub(); reader.clear(); reader.setItems("1", "2", "3", "4", "5"); factory.setItemReader(reader); writer.clear(); factory.setItemWriter(writer); processor.clear(); factory.setItemProcessor(processor); writer.setFailures("1", "2", "3", "4", "5"); Step step = factory.getObject(); stepExecution = jobExecution.createStepExecution(factory.getName()); repository.add(stepExecution); step.execute(stepExecution); assertEquals(BatchStatus.COMPLETED, stepExecution.getStatus()); assertEquals("[]", writer.getCommitted().toString()); assertEquals("[]", processor.getCommitted().toString()); List<String> processed = new ArrayList<String>(processor.getProcessed()); Collections.sort(processed); assertEquals("[1, 1, 2, 2, 3, 3, 4, 4, 5, 5]", processed.toString()); assertEquals(5, stepExecution.getSkipCount()); } catch (Throwable e) { logger.info("Failed on iteration " + i + " of " + MAX_COUNT); throw e; } } }
From source file:org.springframework.batch.core.test.step.MapRepositoryFaultTolerantStepFactoryBeanRollbackTests.java
@SuppressWarnings("unchecked") @Before/* w ww . j a v a2s . c om*/ public void setUp() throws Exception { reader = new SkipReaderStub(); writer = new SkipWriterStub(); processor = new SkipProcessorStub(); factory = new FaultTolerantStepFactoryBean<String, String>(); factory.setTransactionManager(transactionManager); factory.setBeanName("stepName"); factory.setCommitInterval(3); ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor(); taskExecutor.setCorePoolSize(3); taskExecutor.setMaxPoolSize(6); taskExecutor.setQueueCapacity(0); taskExecutor.afterPropertiesSet(); factory.setTaskExecutor(taskExecutor); factory.setSkipLimit(10); factory.setSkippableExceptionClasses(getExceptionMap(Exception.class)); }
From source file:org.springframework.batch.core.test.step.MapRepositoryFaultTolerantStepFactoryBeanTests.java
@Before public void setUp() throws Exception { reader = new SkipReaderStub(); writer = new SkipWriterStub(); processor = new SkipProcessorStub(); factory = new FaultTolerantStepFactoryBean<String, String>(); factory.setBeanName("stepName"); factory.setTransactionManager(transactionManager); factory.setCommitInterval(3);//from w w w . j a va2s. c o m ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor(); taskExecutor.setCorePoolSize(3); taskExecutor.setMaxPoolSize(6); taskExecutor.setQueueCapacity(0); taskExecutor.afterPropertiesSet(); factory.setTaskExecutor(taskExecutor); }