use of org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor in project xm-ms-entity by xm-online.
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("entity-Executor-");
return new ExceptionHandlingAsyncTaskExecutor(executor);
}
use of org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor in project spring-framework by spring-projects.
the class ExecutorBeanDefinitionParserTests method defaultExecutor.
@Test
public void defaultExecutor() throws Exception {
ThreadPoolTaskExecutor executor = this.context.getBean("default", ThreadPoolTaskExecutor.class);
assertThat(getCorePoolSize(executor)).isEqualTo(1);
assertThat(getMaxPoolSize(executor)).isEqualTo(Integer.MAX_VALUE);
assertThat(getQueueCapacity(executor)).isEqualTo(Integer.MAX_VALUE);
assertThat(getKeepAliveSeconds(executor)).isEqualTo(60);
assertThat(getAllowCoreThreadTimeOut(executor)).isFalse();
FutureTask<String> task = new FutureTask<>(() -> "foo");
executor.execute(task);
assertThat(task.get()).isEqualTo("foo");
}
use of org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor in project CzechIdMng by bcvsolutions.
the class AsyncConfig method eventExecutor.
/**
* Executor for event processing. Common async pool is not reused - event processing has higher priority than LRT.
* Both pools should be processed parallel, not blocked.
* Scaled for combination I/O operations (mainly) and computing (e.g. account management, provisioning) event processing.
* Uses cpu count + 1 as default pool size,
*
* @return
*/
@Bean(name = SchedulerConfiguration.EVENT_EXECUTOR_NAME)
public Executor eventExecutor() {
int cpuCount = Runtime.getRuntime().availableProcessors();
// 5
int poolSize = cpuCount + 1;
//
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
int corePoolSize = env.getProperty(SchedulerConfiguration.PROPERTY_EVENT_EXECUTOR_CORE_POOL_SIZE, Integer.class, poolSize);
// ~5
executor.setCorePoolSize(corePoolSize);
int maxPoolSize = env.getProperty(SchedulerConfiguration.PROPERTY_EVENT_EXECUTOR_MAX_POOL_SIZE, Integer.class, corePoolSize * 2);
// ~10
executor.setMaxPoolSize(maxPoolSize);
int queueCapacity = env.getProperty(SchedulerConfiguration.PROPERTY_EVENT_EXECUTOR_QUEUE_CAPACITY, Integer.class, SchedulerConfiguration.DEFAULT_EVENT_EXECUTOR_QUEUE_CAPACITY);
executor.setQueueCapacity(queueCapacity);
executor.setThreadPriority(env.getProperty(SchedulerConfiguration.PROPERTY_EVENT_EXECUTOR_THREAD_PRIORITY, Integer.class, 6));
executor.setThreadNamePrefix("event-task-executor-");
// @Beta - TODO: application context closed listener
executor.setWaitForTasksToCompleteOnShutdown(true);
// MODE_INHERITABLETHREADLOCAL mode is not recommended in environment where thread pools are used (old SecurityContext can be reused in next thread using.).
// Instead that the DelegatingSecurityContextRunnable is used for delegating the SecurityContext to child the thread.
// Same is applies for TransactionContext. You have to use DelegatingTransactionContextRunnable for delegating to the child thread.
// Beware, you have to wrap every new Thread to this delegate objects (wrappers).
executor.setTaskDecorator(runnable -> new DelegatingSecurityContextRunnable(new DelegatingTransactionContextRunnable(runnable)));
executor.setAwaitTerminationSeconds(30);
executor.initialize();
//
LOG.info("Event executor is initialized: corePoolSize [{}], maxPoolSize [{}], queueCapacity [{}]", corePoolSize, maxPoolSize, queueCapacity);
//
return executor;
}
use of org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor in project uplace.es by Uplace.
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("uplace-Executor-");
return new ExceptionHandlingAsyncTaskExecutor(executor);
}
use of org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor in project anki-battle-showcase by adessoAG.
the class AnkiBattleApplication method asyncExecutor.
@Bean
public Executor asyncExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(2);
executor.setMaxPoolSize(2);
executor.setQueueCapacity(500);
executor.initialize();
return executor;
}
Aggregations