use of org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor in project camel by apache.
the class XQueryConcurrencyTest method testConcurrency.
@Test
public void testConcurrency() throws Exception {
int total = 1000;
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedMessageCount(total);
// 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();
}
use of org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor in project opennms by OpenNMS.
the class CollectionCommanderStarter method start.
public void start() {
ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
taskExecutor.setCorePoolSize(4);
taskExecutor.initialize();
taskExecutor.setMaxPoolSize(4);
taskExecutor.setQueueCapacity(8);
taskExecutor.initialize();
Long startTime = System.currentTimeMillis();
Integer i = 0;
while (i < 100) {
CollectionTask ct = new CollectionTask(1200, "SNMP_All_Metrics");
PooledJobPublisher jobPublisher = new PooledJobPublisher(ct);
taskExecutor.execute(jobPublisher);
i++;
}
logger.info("All started '{}'ms", System.currentTimeMillis() - startTime);
Boolean done = false;
while (!done) {
if (taskExecutor.getActiveCount() == 0) {
logger.info("Tasks active '{}'", taskExecutor.getActiveCount());
logger.info("All done '{}'ms", System.currentTimeMillis() - startTime);
taskExecutor.shutdown();
done = true;
} else {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
logger.error("'{}'", e.getMessage());
}
}
}
}
use of org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor in project zipkin by openzipkin.
the class ZipkinMySQLStorageAutoConfiguration method executor.
@Bean
@ConditionalOnMissingBean(Executor.class)
Executor executor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setThreadNamePrefix("ZipkinMySQLStorage-");
executor.initialize();
return executor;
}
use of org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor in project camel by apache.
the class JmsConcurrentConsumersTest method testConcurrentConsumersWithReply.
@Test
public void testConcurrentConsumersWithReply() throws Exception {
// latch for the 5 exchanges we expect
final CountDownLatch latch = new CountDownLatch(5);
// 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 count = i;
executor.execute(new Runnable() {
public void run() {
// request body is InOut pattern and thus we expect a reply (JMSReply)
Object response = template.requestBody("activemq:a", "World #" + count);
assertEquals("Bye World #" + count, response);
latch.countDown();
}
});
}
long start = System.currentTimeMillis();
// wait for test completion, timeout after 30 sec to let other unit test run to not wait forever
assertTrue(latch.await(30000L, TimeUnit.MILLISECONDS));
assertEquals("Latch should be zero", 0, latch.getCount());
long delta = System.currentTimeMillis() - start;
assertTrue("Should be faster than 20000 millis, took " + delta + " millis", delta < 20000L);
executor.shutdown();
}
use of org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor in project camel by apache.
the class DefaultJmsMessageListenerContainer method stop.
@Override
public void stop() throws JmsException {
if (logger.isDebugEnabled()) {
logger.debug("Stopping listenerContainer: " + this + " with cacheLevel: " + getCacheLevel() + " and sharedConnectionEnabled: " + sharedConnectionEnabled());
}
super.stop();
if (taskExecutor instanceof ThreadPoolTaskExecutor) {
ThreadPoolTaskExecutor executor = (ThreadPoolTaskExecutor) taskExecutor;
executor.destroy();
}
}
Aggregations