use of org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor in project tutorials by eugenp.
the class AsyncConfiguration method getAsyncExecutor.
@Override
@Bean(name = "taskExecutor")
public Executor getAsyncExecutor() {
log.debug("Creating Async Task Executor");
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(jHipsterProperties.getAsync().getCorePoolSize());
executor.setMaxPoolSize(jHipsterProperties.getAsync().getMaxPoolSize());
executor.setQueueCapacity(jHipsterProperties.getAsync().getQueueCapacity());
executor.setThreadNamePrefix("baeldung-Executor-");
return new ExceptionHandlingAsyncTaskExecutor(executor);
}
use of org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor in project cetc by DiscoverForever.
the class AsyncConfiguration method getAsyncExecutor.
@Override
@Bean(name = "taskExecutor")
public Executor getAsyncExecutor() {
log.debug("Creating Async Task Executor");
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(jHipsterProperties.getAsync().getCorePoolSize());
executor.setMaxPoolSize(jHipsterProperties.getAsync().getMaxPoolSize());
executor.setQueueCapacity(jHipsterProperties.getAsync().getQueueCapacity());
executor.setThreadNamePrefix("cetc-Executor-");
return new ExceptionHandlingAsyncTaskExecutor(executor);
}
use of org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor in project spring-integration by spring-projects.
the class CallerBlocksPolicyTests method test1.
@Test
public void test1() throws Exception {
final ThreadPoolTaskExecutor te = new ThreadPoolTaskExecutor();
te.setCorePoolSize(2);
te.setMaxPoolSize(2);
te.setQueueCapacity(1);
te.setRejectedExecutionHandler(new CallerBlocksPolicy(10000));
te.initialize();
final AtomicReference<Throwable> e = new AtomicReference<Throwable>();
final CountDownLatch latch = new CountDownLatch(3);
te.execute(() -> {
try {
Runnable foo = new Runnable() {
@Override
public void run() {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new RuntimeException();
}
latch.countDown();
}
};
te.execute(foo);
// this one will be queued
te.execute(foo);
// this one will be blocked and successful later
te.execute(foo);
} catch (TaskRejectedException tre) {
e.set(tre.getCause());
}
});
assertTrue(latch.await(10, TimeUnit.SECONDS));
assertNull(e.get());
te.destroy();
}
use of org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor in project spring-integration by spring-projects.
the class TcpNioConnectionTests method compositeExecutor.
private CompositeExecutor compositeExecutor() {
ThreadPoolTaskExecutor ioExec = new ThreadPoolTaskExecutor();
ioExec.setCorePoolSize(2);
ioExec.setMaxPoolSize(4);
ioExec.setQueueCapacity(0);
ioExec.setThreadNamePrefix("io-");
ioExec.setRejectedExecutionHandler(new AbortPolicy());
ioExec.initialize();
ThreadPoolTaskExecutor assemblerExec = new ThreadPoolTaskExecutor();
assemblerExec.setCorePoolSize(2);
assemblerExec.setMaxPoolSize(5);
assemblerExec.setQueueCapacity(0);
assemblerExec.setThreadNamePrefix("assembler-");
assemblerExec.setRejectedExecutionHandler(new AbortPolicy());
assemblerExec.initialize();
return new CompositeExecutor(ioExec, assemblerExec);
}
use of org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor in project irida by phac-nml.
the class IridaApiServicesConfig method uploadExecutor.
/**
* @return An Executor for handling uploads to Galaxy.
*/
@Bean
public Executor uploadExecutor() {
ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
taskExecutor.setCorePoolSize(4);
taskExecutor.setMaxPoolSize(8);
taskExecutor.setQueueCapacity(16);
taskExecutor.setThreadPriority(Thread.MIN_PRIORITY);
return taskExecutor;
}
Aggregations