hejianhao
2026-08-18 84c81837d6465ee3f768291ea1f2859e322bd1b4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package com.tcm.training.admin.config;
 
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
 
import java.util.concurrent.Executor;
 
/**
 * 异步任务线程池配置。
 */
@Configuration
public class AsyncTaskExecutorConfig {
 
    /**
     * 创建活动通知分发线程池,避免后台创建通知时阻塞请求线程。
     */
    @Bean("activityNoticeTaskExecutor")
    public Executor activityNoticeTaskExecutor() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setThreadNamePrefix("activity-notice-");
        executor.setCorePoolSize(2);
        executor.setMaxPoolSize(4);
        executor.setQueueCapacity(200);
        executor.setWaitForTasksToCompleteOnShutdown(true);
        executor.setAwaitTerminationSeconds(30);
        executor.initialize();
        return executor;
    }
}