package org.example.ThreadConfig; 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(400); // 核心线程数 executor.setMaxPoolSize(1200); // 最大线程数 executor.setQueueCapacity(1500); // 队列容量 executor.setKeepAliveSeconds(60); // 线程空闲时的存活时间为60秒 executor.setThreadNamePrefix("MexcThread-"); // 线程名称的前缀 executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy()); // 使用 CallerRunsPolicy 拒绝策略 return executor; } }