SpringBoot 线程池的配置
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
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 ExecutorConfig {
private static final Logger logger = LoggerFactory.getLogger(ExecutorConfig.class);
public static Integer smsAsynSize = Runtime.getRuntime().availableProcessors();
@Bean
public Executor asyncPromiseExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(smsAsynSize);
executor.setQueueCapacity(smsAsynSize*5);
executor.setMaxPoolSize(smsAsynSize*2);
executor.setThreadNamePrefix("A-Thread");
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
executor.initialize();
logger.info("线程池A-Thread配置成功");
return executor;
}