List of usage examples for org.springframework.scheduling.concurrent ThreadPoolTaskExecutor setAllowCoreThreadTimeOut
public void setAllowCoreThreadTimeOut(boolean allowCoreThreadTimeOut)
From source file:com.ciphertool.zodiacengine.genetic.algorithms.ConcurrentBasicGeneticAlgorithmTest.java
@BeforeClass public static void setUp() { FitnessEvaluator fitnessEvaluator = new CipherSolutionKnownSolutionFitnessEvaluator(); fitnessEvaluator.setGeneticStructure(zodiac408); CrossoverAlgorithm crossoverAlgorithm = new LowestCommonGroupCrossoverAlgorithm(); crossoverAlgorithm.setFitnessEvaluator(fitnessEvaluator); SingleSequenceMutationAlgorithm mutationAlgorithm = new SingleSequenceMutationAlgorithm(); mutationAlgorithm.setSequenceDao(new PlaintextSequenceDao()); ProbabilisticSelectionAlgorithm selectionAlgorithm = new ProbabilisticSelectionAlgorithm(); Selector selector = new RouletteSelector(); GeneticAlgorithmStrategy geneticAlgorithmStrategy = new GeneticAlgorithmStrategy(zodiac408, POPULATION_SIZE, LIFESPAN, MAX_GENERATIONS, SURVIVAL_RATE, MUTATION_RATE, MAX_MUTATIONS_PER_INDIVIDUAL, CROSSOVER_RATE, MUTATE_DURING_CROSSOVER, fitnessEvaluator, crossoverAlgorithm, mutationAlgorithm, selectionAlgorithm, selector); population.setBreeder(solutionBreederMock); population.setSelector(selector);//from ww w.j a va2s. c o m ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor(); taskExecutor.setCorePoolSize(MAX_THREADS); taskExecutor.setMaxPoolSize(MAX_THREADS); taskExecutor.setQueueCapacity(THREAD_EXECUTOR_QUEUE_CAPACITY); taskExecutor.setKeepAliveSeconds(1); taskExecutor.setAllowCoreThreadTimeOut(true); taskExecutor.initialize(); population.setTaskExecutor(taskExecutor); geneticAlgorithm = new ConcurrentBasicGeneticAlgorithm(); geneticAlgorithm.setPopulation(population); geneticAlgorithm.setStrategy(geneticAlgorithmStrategy); ((ConcurrentBasicGeneticAlgorithm) geneticAlgorithm).setTaskExecutor(taskExecutor); ExecutionStatisticsDao executionStatisticsDaoMock = mock(ExecutionStatisticsDao.class); ((ConcurrentBasicGeneticAlgorithm) geneticAlgorithm).setExecutionStatisticsDao(executionStatisticsDaoMock); }
From source file:com.ciphertool.zodiacengine.genetic.PopulationTest.java
@BeforeClass public static void setUp() { population.setSelector(new RouletteSelector()); population.setBreeder(solutionBreederMock); ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor(); taskExecutor.setCorePoolSize(4);/*from w w w . ja v a 2 s. com*/ taskExecutor.setMaxPoolSize(4); taskExecutor.setQueueCapacity(100); taskExecutor.setKeepAliveSeconds(1); taskExecutor.setAllowCoreThreadTimeOut(true); taskExecutor.initialize(); population.setTaskExecutor(taskExecutor); CipherSolutionKnownSolutionFitnessEvaluator cipherSolutionKnownSolutionFitnessEvaluator = new CipherSolutionKnownSolutionFitnessEvaluator(); cipherSolutionKnownSolutionFitnessEvaluator.setGeneticStructure(zodiac408); population.setFitnessEvaluator(cipherSolutionKnownSolutionFitnessEvaluator); population.setLifespan(LIFESPAN); population.setFitnessComparator(new AscendingFitnessComparator()); dummySolution = knownSolution.clone(); dummySolution.getGenes().get(0).insertSequence(0, new PlaintextSequence(0, "i", dummySolution.getGenes().get(0))); }
From source file:com.ciphertool.zodiacengine.genetic.algorithms.BasicGeneticAlgorithmTest.java
@BeforeClass public static void setUp() { FitnessEvaluator fitnessEvaluator = new CipherSolutionKnownSolutionFitnessEvaluator(); fitnessEvaluator.setGeneticStructure(zodiac408); CrossoverAlgorithm crossoverAlgorithm = new LowestCommonGroupCrossoverAlgorithm(); crossoverAlgorithm.setFitnessEvaluator(fitnessEvaluator); SingleSequenceMutationAlgorithm mutationAlgorithm = new SingleSequenceMutationAlgorithm(); mutationAlgorithm.setSequenceDao(new PlaintextSequenceDao()); ProbabilisticSelectionAlgorithm selectionAlgorithm = new ProbabilisticSelectionAlgorithm(); Selector selector = new RouletteSelector(); GeneticAlgorithmStrategy geneticAlgorithmStrategy = new GeneticAlgorithmStrategy(zodiac408, POPULATION_SIZE, LIFESPAN, MAX_GENERATIONS, SURVIVAL_RATE, MUTATION_RATE, MAX_MUTATIONS_PER_INDIVIDUAL, CROSSOVER_RATE, MUTATE_DURING_CROSSOVER, fitnessEvaluator, crossoverAlgorithm, mutationAlgorithm, selectionAlgorithm, selector); population.setBreeder(solutionBreederMock); population.setSelector(selector);/*from w w w. jav a2s. co m*/ ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor(); taskExecutor.setCorePoolSize(MAX_THREADS); taskExecutor.setMaxPoolSize(MAX_THREADS); taskExecutor.setQueueCapacity(THREAD_EXECUTOR_QUEUE_CAPACITY); taskExecutor.setKeepAliveSeconds(1); taskExecutor.setAllowCoreThreadTimeOut(true); taskExecutor.initialize(); population.setTaskExecutor(taskExecutor); geneticAlgorithm = new BasicGeneticAlgorithm(); geneticAlgorithm.setPopulation(population); geneticAlgorithm.setStrategy(geneticAlgorithmStrategy); ExecutionStatisticsDao executionStatisticsDaoMock = mock(ExecutionStatisticsDao.class); ((BasicGeneticAlgorithm) geneticAlgorithm).setExecutionStatisticsDao(executionStatisticsDaoMock); }
From source file:com.epam.ta.reportportal.core.configs.JobsConfiguration.java
@Bean(name = "saveLogsTaskExecutor") public TaskExecutor saveLogsTaskExecutor() { ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); executor.setCorePoolSize(20);//w ww . ja v a 2s .c o m executor.setMaxPoolSize(200); executor.setQueueCapacity(400); executor.setAllowCoreThreadTimeOut(true); executor.setThreadNamePrefix("logs-task-exec"); executor.setRejectedExecutionHandler(new java.util.concurrent.ThreadPoolExecutor.CallerRunsPolicy()); return executor; }
From source file:com.epam.ta.reportportal.core.configs.JobsConfiguration.java
@Bean(name = "autoAnalyzeTaskExecutor") public TaskExecutor autoAnalyzeTaskExecutor() { final ThreadPoolTaskExecutor threadPoolTaskExecutor = new ThreadPoolTaskExecutor(); threadPoolTaskExecutor.setCorePoolSize(10); threadPoolTaskExecutor.setMaxPoolSize(30); threadPoolTaskExecutor.setQueueCapacity(200); threadPoolTaskExecutor.setAllowCoreThreadTimeOut(true); threadPoolTaskExecutor.setThreadNamePrefix("auto-analyze-exec"); return threadPoolTaskExecutor; }
From source file:com.apress.prospringintegration.concurrency.taskexecutorexample.TaskExecutorExampleConfiguration.java
@Bean public ThreadPoolTaskExecutor threadPoolTaskExecutor() { ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); executor.setCorePoolSize(50);// www .jav a 2 s . c om executor.setDaemon(false); executor.setWaitForTasksToCompleteOnShutdown(true); executor.setMaxPoolSize(100); executor.setAllowCoreThreadTimeOut(true); 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 w w 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 w w. j a 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 = 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);/*from w ww . ja v a 2 s.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);/*from w w w .ja va2 s .c o m*/ executor.setQueueCapacity(Integer.MAX_VALUE); executor.setAllowCoreThreadTimeOut(true); return executor; }