Java Code Examples for org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor#setTaskDecorator()

The following examples show how to use org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor#setTaskDecorator() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ThreadUtil.java    From Milkomeda with MIT License 6 votes vote down vote up
/**
 * 自定义配置ThreadPoolTaskExecutor
 *
 * @param taskExecutor     ThreadPoolTaskExecutor
 * @param prefix           前辍
 * @param corePoolSize     核心池大小
 * @param maxPoolSize      最大线程池数
 * @param queueCapacity    队列容量
 * @param keepAliveSeconds 线程保存存活时间
 */
public static void configTaskExecutor(ThreadPoolTaskExecutor taskExecutor, String prefix, int corePoolSize, int maxPoolSize, int queueCapacity, int keepAliveSeconds) {
    // 线程池维护线程的最少数量
    taskExecutor.setCorePoolSize(corePoolSize);
    // 线程池维护线程的最大数量
    taskExecutor.setMaxPoolSize(maxPoolSize);
    // 线程池所使用的缓冲队列
    taskExecutor.setQueueCapacity(queueCapacity);
    // 线程池维护线程所允许的空闲时间
    taskExecutor.setKeepAliveSeconds(keepAliveSeconds);
    // 调度器shutdown被调用时等待当前被调度的任务完成
    taskExecutor.setWaitForTasksToCompleteOnShutdown(true);
    // 等待时长
    taskExecutor.setAwaitTerminationSeconds(60);
    taskExecutor.setThreadNamePrefix(prefix);
    // 线程池对拒绝任务(无线程可用)的处理策略,目前只支持AbortPolicy、CallerRunsPolicy,默认为后者
    taskExecutor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
    taskExecutor.setTaskDecorator(new RequestContextDecorator());
    taskExecutor.initialize();
}
 
Example 2
Source File: AppConfig.java    From staffjoy with MIT License 5 votes vote down vote up
@Bean(name=ASYNC_EXECUTOR_NAME)
public Executor asyncExecutor() {
    ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    // for passing in request scope context
    executor.setTaskDecorator(new ContextCopyingDecorator());
    executor.setCorePoolSize(3);
    executor.setMaxPoolSize(5);
    executor.setQueueCapacity(100);
    executor.setWaitForTasksToCompleteOnShutdown(true);
    executor.setThreadNamePrefix("AsyncThread-");
    executor.initialize();
    return executor;
}
 
Example 3
Source File: AppConfig.java    From staffjoy with MIT License 5 votes vote down vote up
@Bean(name=ASYNC_EXECUTOR_NAME)
public Executor asyncExecutor() {
    ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    // for passing in request scope context
    executor.setTaskDecorator(new ContextCopyingDecorator());
    executor.setCorePoolSize(3);
    executor.setMaxPoolSize(5);
    executor.setQueueCapacity(100);
    executor.setWaitForTasksToCompleteOnShutdown(true);
    executor.setThreadNamePrefix("AsyncThread-");
    executor.initialize();
    return executor;
}
 
Example 4
Source File: AppConfig.java    From staffjoy with MIT License 5 votes vote down vote up
@Bean(name=ASYNC_EXECUTOR_NAME)
public Executor asyncExecutor() {
    ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    // for passing in request scope context
    executor.setTaskDecorator(new ContextCopyingDecorator());
    executor.setCorePoolSize(3);
    executor.setMaxPoolSize(5);
    executor.setQueueCapacity(100);
    executor.setWaitForTasksToCompleteOnShutdown(true);
    executor.setThreadNamePrefix("AsyncThread-");
    executor.initialize();
    return executor;
}
 
Example 5
Source File: AppConfig.java    From staffjoy with MIT License 5 votes vote down vote up
@Bean(name=ASYNC_EXECUTOR_NAME)
public Executor asyncExecutor() {
    ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    executor.setTaskDecorator(new ContextCopyingDecorator());
    executor.setCorePoolSize(3);
    executor.setMaxPoolSize(5);
    executor.setQueueCapacity(100);
    executor.setWaitForTasksToCompleteOnShutdown(true);
    executor.setThreadNamePrefix("AsyncThread-");
    executor.initialize();
    return executor;
}
 
Example 6
Source File: AsyncConfiguration.java    From dk-foundation with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Bean
@Override
public Executor getAsyncExecutor() {
    ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    executor.setCorePoolSize(10);
    executor.setMaxPoolSize(10);
    executor.setQueueCapacity(100);
    executor.setThreadNamePrefix("async-pool-");
    executor.setTaskDecorator(new MdcTaskDecorator());
    executor.setWaitForTasksToCompleteOnShutdown(true);
    executor.initialize();
    return executor;
}
 
Example 7
Source File: AsyncConfig.java    From Pixiv-Illustration-Collection-Backend with Apache License 2.0 5 votes vote down vote up
@Bean
@Override
public Executor getAsyncExecutor() {
    ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    executor.setCorePoolSize(10);
    executor.setMaxPoolSize(10);
    executor.setQueueCapacity(100000);
    executor.setThreadNamePrefix("async-pool-");
    executor.setTaskDecorator(new MdcTaskDecorator());
    executor.setWaitForTasksToCompleteOnShutdown(true);
    executor.initialize();
    return executor;
}
 
Example 8
Source File: AsyncConfig.java    From SpringBootMultiTenancy with MIT License 5 votes vote down vote up
@Override
public Executor getAsyncExecutor() {
    ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();

    executor.setCorePoolSize(7);
    executor.setMaxPoolSize(42);
    executor.setQueueCapacity(11);
    executor.setThreadNamePrefix("TenantAwareTaskExecutor-");
    executor.setTaskDecorator(new TenantAwareTaskDecorator());
    executor.initialize();

    return executor;
}
 
Example 9
Source File: AsyncTaskConfiguration.java    From onetwo with Apache License 2.0 5 votes vote down vote up
@Bean(ASYNC_TASK_BEAN_NAME)
@ConditionalOnMissingBean(AsyncTaskExecutor.class)
   public AsyncTaskExecutor mvcAsyncTaskExecutor(SimpleTaskDecorator simpleTaskDecorator) {
       ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
       executor.setCorePoolSize(asyncTaskProperties.getCorePoolSize());
       executor.setMaxPoolSize(asyncTaskProperties.getMaxPoolSize());
       executor.setQueueCapacity(asyncTaskProperties.getQueueCapacity());
       executor.setTaskDecorator(simpleTaskDecorator);
       return executor;
   }
 
Example 10
Source File: AppConfig.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
@Bean
public AsyncTaskExecutor intermediateBuilderExecutor() {
    ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    executor.setCorePoolSize(intermediateCorePoolSize);
    executor.setQueueCapacity(intermediateQueueCapacity);
    executor.setThreadNamePrefix("intermediateBuilderExecutor-");
    executor.setTaskDecorator(new MDCCleanerTaskDecorator());
    executor.initialize();
    return executor;
}
 
Example 11
Source File: AppConfig.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
@Bean
public AsyncTaskExecutor resourceBuilderExecutor() {
    ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    executor.setCorePoolSize(corePoolSize);
    executor.setQueueCapacity(queueCapacity);
    executor.setThreadNamePrefix("resourceBuilderExecutor-");
    executor.setTaskDecorator(new MDCCleanerTaskDecorator());
    executor.initialize();
    return executor;
}
 
Example 12
Source File: UsersyncConfig.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
@Bean(name = USERSYNC_TASK_EXECUTOR)
public AsyncTaskExecutor usersyncTaskExecutor() {
    ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    executor.setCorePoolSize(usersyncCorePoolSize);
    executor.setQueueCapacity(usersyncQueueCapacity);
    executor.setThreadNamePrefix("usersyncExecutor-");
    executor.setTaskDecorator(
            new CompositeTaskDecorator(
                    List.of(new MDCCleanerTaskDecorator(), new ActorCrnTaskDecorator())));
    executor.initialize();
    return executor;
}
 
Example 13
Source File: AppConfig.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
@Bean
@Primary
public AsyncTaskExecutor intermediateBuilderExecutor() {
    ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    executor.setCorePoolSize(intermediateCorePoolSize);
    executor.setQueueCapacity(intermediateQueueCapacity);
    executor.setThreadNamePrefix("intermediateBuilderExecutor-");
    executor.setTaskDecorator(new MDCCleanerTaskDecorator());
    executor.initialize();
    return executor;
}
 
Example 14
Source File: AppConfig.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
@Bean
@Primary
public AsyncTaskExecutor intermediateBuilderExecutor() {
    ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    executor.setCorePoolSize(intermediateCorePoolSize);
    executor.setQueueCapacity(intermediateQueueCapacity);
    executor.setThreadNamePrefix("intermediateBuilderExecutor-");
    executor.setTaskDecorator(new MDCCleanerTaskDecorator());
    executor.initialize();
    return executor;
}
 
Example 15
Source File: AppConfig.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
@Bean
public AsyncTaskExecutor intermediateBuilderExecutor() {
    ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    executor.setCorePoolSize(intermediateCorePoolSize);
    executor.setQueueCapacity(intermediateQueueCapacity);
    executor.setThreadNamePrefix("intermediateBuilderExecutor-");
    executor.setTaskDecorator(new MDCCleanerTaskDecorator());
    executor.setWaitForTasksToCompleteOnShutdown(true);
    executor.setAwaitTerminationSeconds(AWAIT_TERMINATION_SECONDS);
    executor.initialize();
    return executor;
}
 
Example 16
Source File: AppConfig.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
@Bean
public AsyncTaskExecutor resourceBuilderExecutor() {
    ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    executor.setCorePoolSize(corePoolSize);
    executor.setQueueCapacity(queueCapacity);
    executor.setThreadNamePrefix("resourceBuilderExecutor-");
    executor.setTaskDecorator(new MDCCleanerTaskDecorator());
    executor.setWaitForTasksToCompleteOnShutdown(true);
    executor.setAwaitTerminationSeconds(AWAIT_TERMINATION_SECONDS);
    executor.initialize();
    return executor;
}