| | |
| | | import org.springframework.context.annotation.Configuration; |
| | | import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; |
| | | |
| | | import javax.annotation.PreDestroy; |
| | | import java.util.concurrent.ThreadPoolExecutor; |
| | | |
| | | /** |
| | |
| | | executor.setMaxPoolSize(150); // 最大线程数, 适当设置以避免资源耗尽 |
| | | executor.setQueueCapacity(200); // 队列容量, 适当限制以避免请求堆积 |
| | | executor.setKeepAliveSeconds(30); // 线程空闲时的存活时间为30秒,减少系统开销 |
| | | executor.setThreadNamePrefix("Thread-"); // 线程名称的前缀 |
| | | executor.setThreadNamePrefix("wsThread-"); // 线程名称的前缀 |
| | | |
| | | // 使用 CallerRunsPolicy 拒绝策略,以减少任务被拒绝时带来的负担 |
| | | executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy()); |