package com.imyeyu.api.config; import lombok.Data; import lombok.extern.slf4j.Slf4j; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; import java.util.concurrent.ThreadPoolExecutor; /** * 线程池配置 * * @author 夜雨 * @since 2023-08-21 16:31 */ @Data @Slf4j @Configuration public class ThreadPoolConfig { @Bean(name = "threadPoolTaskExecutor") public ThreadPoolTaskExecutor threadPoolTaskExecutor() { ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); executor.setCorePoolSize(16); executor.setMaxPoolSize(32); executor.setQueueCapacity(16); executor.setKeepAliveSeconds(60); executor.setAwaitTerminationSeconds(60); executor.setThreadNamePrefix("thread-pool-task-executor-"); executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy()); executor.initialize(); return executor; } }