1
zj
2024-07-15 3e94b30057748e7b89bf52185a98412882d8524e
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
package org.example.websocket.config;
 
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
 
import java.util.concurrent.ThreadPoolExecutor;
 
/**
 * @program: dabaogp
 * @description:
 * @create: 2024-06-25 16:37
 **/
@Configuration
public class AsyncConfiguration {
 
    @Bean(name = "threadPoolTaskExecutor")
    public ThreadPoolTaskExecutor threadPoolTaskExecutor() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setCorePoolSize(5);    //  核心线程数
        executor.setMaxPoolSize(100);    //  最大线程数
        executor.setQueueCapacity(300);    //  队列容量
        executor.setKeepAliveSeconds(60);    //  线程空闲时的存活时间为60秒
        executor.setThreadNamePrefix("MyThread-");    //  线程名称的前缀
        executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());    //  使用  CallerRunsPolicy  拒绝策略
        return executor;
    }
}