| | |
| | | import org.apache.commons.lang3.concurrent.BasicThreadFactory; |
| | | import org.springframework.context.annotation.Bean; |
| | | import org.springframework.context.annotation.Configuration; |
| | | import org.springframework.context.annotation.Primary; |
| | | import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; |
| | | import java.util.concurrent.ScheduledExecutorService; |
| | | import java.util.concurrent.ScheduledThreadPoolExecutor; |
| | |
| | | /** |
| | | * 线程池配置 |
| | | * |
| | | * @author ruoyi |
| | | * @author ard |
| | | **/ |
| | | @Configuration |
| | | public class ThreadPoolConfig |
| | |
| | | private int keepAliveSeconds = 300; |
| | | |
| | | @Bean(name = "threadPoolTaskExecutor") |
| | | @Primary |
| | | public ThreadPoolTaskExecutor threadPoolTaskExecutor() |
| | | { |
| | | ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); |
| | |
| | | } |
| | | }; |
| | | } |
| | | @Bean("mediaVideoExecutor") |
| | | public ThreadPoolTaskExecutor mediaVideoExecutor() { |
| | | ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); |
| | | executor.setCorePoolSize(10); // 核心线程数:同时处理视频的核心线程数 |
| | | executor.setMaxPoolSize(10); // 最大线程数:线程池不会扩展超过这个数量 |
| | | executor.setQueueCapacity(50); // 队列容量:等待执行的任务数量,之前20太小可能会拒绝任务 |
| | | executor.setThreadNamePrefix("media-video-"); |
| | | |
| | | // 当线程池和队列都满时的拒绝策略 |
| | | executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy()); |
| | | |
| | | executor.initialize(); |
| | | return executor; |
| | | } |
| | | @Bean("mediaPicExecutor") |
| | | public ThreadPoolTaskExecutor mediaPicExecutor() { |
| | | ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); |
| | | executor.setCorePoolSize(10); // 核心线程数:同时处理视频的核心线程数 |
| | | executor.setMaxPoolSize(10); // 最大线程数:线程池不会扩展超过这个数量 |
| | | executor.setQueueCapacity(50); // 队列容量:等待执行的任务数量,之前20太小可能会拒绝任务 |
| | | executor.setThreadNamePrefix("media-pic-"); |
| | | |
| | | // 当线程池和队列都满时的拒绝策略 |
| | | executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy()); |
| | | |
| | | executor.initialize(); |
| | | return executor; |
| | | } |
| | | } |