Search in sources :

Example 56 with ThreadPoolTaskExecutor

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);
}
Also used : ThreadPoolTaskExecutor(org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor) ExceptionHandlingAsyncTaskExecutor(io.github.jhipster.async.ExceptionHandlingAsyncTaskExecutor) Bean(org.springframework.context.annotation.Bean)

Example 57 with ThreadPoolTaskExecutor

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");
}
Also used : FutureTask(java.util.concurrent.FutureTask) ThreadPoolTaskExecutor(org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor) Test(org.junit.jupiter.api.Test)

Example 58 with ThreadPoolTaskExecutor

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;
}
Also used : ThreadPoolTaskExecutor(org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor) DelegatingSecurityContextRunnable(org.springframework.security.concurrent.DelegatingSecurityContextRunnable) Bean(org.springframework.context.annotation.Bean)

Example 59 with ThreadPoolTaskExecutor

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);
}
Also used : ThreadPoolTaskExecutor(org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor) ExceptionHandlingAsyncTaskExecutor(io.github.jhipster.async.ExceptionHandlingAsyncTaskExecutor) Bean(org.springframework.context.annotation.Bean)

Example 60 with ThreadPoolTaskExecutor

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;
}
Also used : ThreadPoolTaskExecutor(org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor) Bean(org.springframework.context.annotation.Bean)

Aggregations

ThreadPoolTaskExecutor (org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor)152 Bean (org.springframework.context.annotation.Bean)72 ExceptionHandlingAsyncTaskExecutor (io.github.jhipster.async.ExceptionHandlingAsyncTaskExecutor)19 Test (org.junit.jupiter.api.Test)19 BigInteger (java.math.BigInteger)16 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)15 RateLimiter (com.google.common.util.concurrent.RateLimiter)14 Test (org.junit.Test)14 Random (java.util.Random)12 ApplicationContext (org.springframework.context.ApplicationContext)12 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)9 Service (org.fisco.bcos.channel.client.Service)9 Credentials (org.fisco.bcos.web3j.crypto.Credentials)9 Web3j (org.fisco.bcos.web3j.protocol.Web3j)9 ChannelEthereumService (org.fisco.bcos.web3j.protocol.channel.ChannelEthereumService)9 TransactionReceipt (org.fisco.bcos.web3j.protocol.core.methods.response.TransactionReceipt)9 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)9 CountDownLatch (java.util.concurrent.CountDownLatch)8 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)6 MDCCleanerTaskDecorator (com.sequenceiq.cloudbreak.concurrent.MDCCleanerTaskDecorator)4