List of usage examples for org.springframework.scheduling.concurrent ThreadPoolTaskExecutor ThreadPoolTaskExecutor
ThreadPoolTaskExecutor
From source file:ch.javaee.basicMvc.config.SchedulingConfig.java
@Override public Executor getAsyncExecutor() { logger.debug("Enter: getAsynchExecutor"); ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); executor.setCorePoolSize(7);/*from ww w . jav a 2 s . c o m*/ executor.setMaxPoolSize(42); executor.setQueueCapacity(11); executor.setThreadNamePrefix("AsyncExecutor-"); executor.initialize(); logger.debug("Exit: getAsynchExecutor"); return executor; }
From source file:org.apache.camel.component.xquery.XQueryURLBasedConcurrencyTest.java
@Test public void testConcurrency() throws Exception { int total = 1000; MockEndpoint mock = getMockEndpoint("mock:result"); mock.expectedMessageCount(total);/*www .j av a2 s .c o m*/ // setup a task executor to be able send the messages in parallel ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); executor.setCorePoolSize(5); executor.afterPropertiesSet(); for (int i = 0; i < 5; i++) { final int threadCount = i; executor.execute(new Runnable() { public void run() { int start = threadCount * 200; for (int i = 0; i < 200; i++) { try { // do some random sleep to simulate spread in user activity Thread.sleep(new Random().nextInt(10)); } catch (InterruptedException e) { // ignore } template.sendBody("direct:start", "<mail><subject>" + (start + i) + "</subject><body>Hello world!</body></mail>"); } } }); } mock.assertIsSatisfied(); // must use bodyAs(String.class) to force DOM to be converted to String XML // for duplication detection mock.assertNoDuplicates(bodyAs(String.class)); executor.shutdown(); }
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 a2 s. co m*/ 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:org.schedoscope.metascope.config.TaskConfiguration.java
@Bean(name = "background") public TaskExecutor backgroundTaskExecutor() { ThreadPoolTaskExecutor threadPoolTaskExecutor = new ThreadPoolTaskExecutor(); threadPoolTaskExecutor.setCorePoolSize(5); threadPoolTaskExecutor.setMaxPoolSize(5); threadPoolTaskExecutor.setWaitForTasksToCompleteOnShutdown(true); return threadPoolTaskExecutor; }
From source file:org.apache.camel.component.xquery.XQueryConcurrencyTest.java
@Test public void testConcurrency() throws Exception { int total = 1000; MockEndpoint mock = getMockEndpoint("mock:result"); mock.expectedMessageCount(total);/*from w w w . java2 s . com*/ // setup a task executor to be able send the messages in parallel ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); executor.setCorePoolSize(5); executor.afterPropertiesSet(); for (int i = 0; i < 5; i++) { final int threadCount = i; executor.execute(new Runnable() { public void run() { int start = threadCount * 200; for (int i = 0; i < 200; i++) { try { // do some random sleep to simulate spread in user activity Thread.sleep(new Random().nextInt(10)); } catch (InterruptedException e) { // ignore } template.sendBody(uri, "<person><id>" + (start + i + 1) + "</id><name>James</name></person>"); } } }); } mock.assertNoDuplicates(body()); assertMockEndpointsSatisfied(); executor.shutdown(); }
From source file:uk.gov.nationalarchives.discovery.taxonomy.common.config.AsyncConfiguration.java
/** * executor dedicated to searches against in memory index * // w w w. j a va 2 s. c o m * @return */ public @Bean ThreadPoolTaskExecutor memorySearchTaskExecutor() { ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); executor.setCorePoolSize(memoryThreadPoolSize); executor.setMaxPoolSize(memoryThreadPoolSize); executor.setQueueCapacity(memoryQueueCapacity); executor.setThreadNamePrefix("memorySearchTaskExecutor-"); executor.initialize(); return executor; }
From source file:org.elasticsoftware.elasticactors.configuration.AppConfiguration.java
@Bean(name = "asyncExecutor") public Executor getAsyncExecutor() { ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); executor.setCorePoolSize(Runtime.getRuntime().availableProcessors()); executor.setMaxPoolSize(Runtime.getRuntime().availableProcessors() * 3); executor.setQueueCapacity(1024);//from w w w . java 2 s . c o m executor.setThreadNamePrefix("ASYNCHRONOUS-ANNOTATION-EXECUTOR-"); executor.initialize(); return executor; }
From source file:com.codependent.niorest.SpringNioRestApplication.java
@Bean public ThreadPoolTaskExecutor executor() { ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); executor.setCorePoolSize(5000); return executor; }
From source file:cn.org.once.cstack.config.AsyncConfiguration.java
@Override @Bean//from w w w . ja va2 s .c om public Executor getAsyncExecutor() { log.debug("Creating Async Task Executor"); ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); executor.setCorePoolSize(5); executor.setMaxPoolSize(50); executor.setWaitForTasksToCompleteOnShutdown(true); executor.setQueueCapacity(10000); executor.setThreadNamePrefix("cloudunit-Executor-"); executor.initialize(); return executor; }
From source file:com.springsource.greenhouse.config.TaskConfig.java
/** * The asynchronous task executor used by the Greenhouse application. */ @Bean public Executor taskExecutor() { return new ThreadPoolTaskExecutor(); }