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;
|
}
|
}
|