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 spring-framework by spring-projects.
the class AbstractMessageBrokerConfiguration method brokerChannelExecutor.
@Bean
public ThreadPoolTaskExecutor brokerChannelExecutor() {
ChannelRegistration reg = getBrokerRegistry().getBrokerChannelRegistration();
ThreadPoolTaskExecutor executor;
if (reg.hasTaskExecutor()) {
executor = reg.taskExecutor().getTaskExecutor();
} else {
// Should never be used
executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(0);
executor.setMaxPoolSize(1);
executor.setQueueCapacity(0);
}
executor.setThreadNamePrefix("brokerChannel-");
return executor;
}
use of org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor in project spring-framework by spring-projects.
the class TaskExecutorRegistration method getTaskExecutor.
protected ThreadPoolTaskExecutor getTaskExecutor() {
ThreadPoolTaskExecutor executor = (this.taskExecutor != null ? this.taskExecutor : new ThreadPoolTaskExecutor());
executor.setCorePoolSize(this.corePoolSize);
executor.setMaxPoolSize(this.maxPoolSize);
executor.setKeepAliveSeconds(this.keepAliveSeconds);
executor.setQueueCapacity(this.queueCapacity);
executor.setAllowCoreThreadTimeOut(true);
return executor;
}
use of org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor in project zipkin by openzipkin.
the class TraceZipkinMySQLStorageAutoConfiguration method executor.
@Bean
@ConditionalOnMissingBean(Executor.class)
public Executor executor(ServerSpanState serverState) {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setThreadNamePrefix("MySQLStorage-");
executor.initialize();
return command -> {
ServerSpan currentSpan = serverState.getCurrentServerSpan();
executor.execute(() -> {
serverState.setCurrentServerSpan(currentSpan);
command.run();
});
};
}
use of org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor in project camel by apache.
the class XQueryURLBasedConcurrencyTest 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("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();
}
Aggregations