List of usage examples for org.springframework.scheduling.concurrent ThreadPoolTaskExecutor initialize
public void initialize()
From source file:com.google.cloud.trace.zipkin.autoconfigure.ZipkinStackdriverStorageAutoConfiguration.java
@Bean(name = "stackdriverExecutor") @ConditionalOnMissingBean(Executor.class) Executor executor() {// w w w .j a v a 2 s. co m ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); executor.setThreadNamePrefix("ZipkinStackdriverStorage-"); executor.setCorePoolSize(storageProperties.getExecutor().getCorePoolSize()); executor.setMaxPoolSize(storageProperties.getExecutor().getMaxPoolSize()); executor.setQueueCapacity(storageProperties.getExecutor().getQueueCapacity()); executor.initialize(); log.info("Configured Executor for ZipkinStackDriver Storage with: {}", storageProperties.getExecutor()); return executor; }
From source file:org.logger.event.web.controller.EventController.java
@Override public Executor getAsyncExecutor() { ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); executor.setCorePoolSize(15);// w w w.j a va 2 s .co m executor.setMaxPoolSize(80); executor.setQueueCapacity(200); executor.setThreadNamePrefix("eventExecutor"); executor.initialize(); return executor; }
From source file:com.bt.aloha.batchtest.PerformanceBatchTest.java
private void restartSimpleSipStack(int numberSimpleSipThreads) { ThreadPoolTaskExecutor threadPoolTaskExecutor = (ThreadPoolTaskExecutor) applicationContext .getBean("taskExecutor"); threadPoolTaskExecutor.destroy();/*from w ww.j a va 2 s . c o m*/ threadPoolTaskExecutor.setCorePoolSize(numberSimpleSipThreads); threadPoolTaskExecutor.initialize(); }
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 .ja v 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 w ww .j ava 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 = 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:com.ethlo.geodata.GeodataServiceImpl.java
public void load() { ensureBaseDirectory();//from www . j a va2 s. c o m final SourceDataInfoSet sourceInfo = geoMetaService.getSourceDataInfo(); if (sourceInfo.isEmpty()) { logger.error( "Cannot start geodata server as there is no data. Please run with 'update' parameter to import data"); System.exit(1); } loadHierarchy(); final ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor(); taskExecutor.setCorePoolSize(3); taskExecutor.setThreadNamePrefix("data-loading-"); taskExecutor.initialize(); taskExecutor.execute(this::loadLocations); taskExecutor.execute(this::loadMbr); taskExecutor.execute(this::loadIps); taskExecutor.setAwaitTerminationSeconds(Integer.MAX_VALUE); taskExecutor.setWaitForTasksToCompleteOnShutdown(true); taskExecutor.shutdown(); //final ResultSet<GeoLocation> result = geoNamesRepository.retrieve(QueryFactory.equal(CqGeonamesRepository.ATTRIBUTE_FEATURE_CODE, "ADM1")); //result.forEach(this::connectAdm1WithCountry); publisher.publishEvent(new DataLoadedEvent(this, DataType.ALL, Operation.LOAD, 1, 1)); }
From source file:com.ciphertool.sentencebuilder.etl.importers.FrequencyListImporterImplTest.java
@Test public void testImportFrequencyList() { ThreadPoolTaskExecutor taskExecutorSpy = spy(new ThreadPoolTaskExecutor()); taskExecutorSpy.setCorePoolSize(4);//from www . j a v a 2 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 = 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 av a 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)); }
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/*w ww . j ava 2s .c o m*/ 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.cloud.sleuth.instrument.async.issues.issue410.Issue410Tests.java
@Bean public Executor poolTaskExecutor() { ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); executor.initialize(); return executor; }