package com.cn.tianji.config; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.scheduling.annotation.AsyncConfigurer; import org.springframework.scheduling.annotation.EnableAsync; import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; import java.util.concurrent.Executor; import java.util.concurrent.ThreadPoolExecutor; @Configuration @EnableAsync public class AsyncConfig implements AsyncConfigurer { @Bean(name = "workingConditionCalculationTaskExecutor") public Executor taskExecutor() { ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); executor.setCorePoolSize(10); // 设置核心线程数 executor.setMaxPoolSize(20); // 设置最大线程数 executor.setQueueCapacity(500); // 设置队列容量 executor.setKeepAliveSeconds(60); // 线程空闲时间 executor.setThreadNamePrefix("WorkingConditionCalculationThread-"); // 设置线程名前缀 executor.setRejectedExecutionHandler(new ThreadPoolExecutor.DiscardPolicy()); // 拒绝策略 executor.initialize(); return executor; } @Override public Executor getAsyncExecutor() { return taskExecutor(); } }