多线程执行定时任务 @author Gao
| 14 | * |
| 15 | */ |
| 16 | @Configuration |
| 17 | @EnableAsync// 开启异步事件的支持 |
| 18 | public class AsyncConfig { |
| 19 | |
| 20 | //@Value("${taskExecutor.async.corePoolSize}") |
| 21 | private final int corePoolSize = 20; |
| 22 | //@Value("${taskExecutor.async.maxPoolSize}") |
| 23 | private final int maxPoolSize = 500; |
| 24 | |
| 25 | |
| 26 | //cms.web.action.quartz.Task.java类topicIndex()方法@Async("taskExecutor_topicIndex")调用 |
| 27 | @Bean |
| 28 | public Executor taskExecutor() { |
| 29 | ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); |
| 30 | executor.setCorePoolSize(corePoolSize);//核心线程池大小 |
| 31 | executor.setMaxPoolSize(maxPoolSize);//最大线程数 |
| 32 | //线程池对拒绝任务(无线程可用)的处理策略 |
| 33 | executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());//处理的方法是运行计算任务,除非ThreadPoolExecutor被关闭,这样的话,任务会被丢弃 |
| 34 | |
| 35 | executor.initialize(); |
| 36 | return executor; |
| 37 | } |
| 38 | |
| 39 | |
| 40 | |
| 41 | @Bean |
| 42 | public Executor taskExecutor_topicIndexComponent_topicIndex() { |
| 43 | ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); |
| 44 | executor.setBeanName("taskExecutor_topicIndexComponent_topicIndex"); |
| 45 | executor.setCorePoolSize(1);//核心线程池大小 |
| 46 | |
| 47 | executor.initialize(); |
| 48 | return executor; |
| 49 | } |
| 50 | @Bean |
| 51 | public Executor taskExecutor_questionIndexComponent_questionIndex() { |
| 52 | ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); |
| 53 | executor.setBeanName("taskExecutor_questionIndexComponent_questionIndex"); |
| 54 | executor.setCorePoolSize(1);//核心线程池大小 |
| 55 | |
| 56 | executor.initialize(); |
| 57 | return executor; |
| 58 | } |
| 59 | @Bean |
| 60 | public Executor taskExecutor_thumbnailComponent_treatmentThumbnail() { |
| 61 | ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); |
| 62 | executor.setBeanName("taskExecutor_thumbnailComponent_treatmentThumbnail"); |
| 63 | executor.setCorePoolSize(1);//核心线程池大小 |
| 64 | |
| 65 | executor.initialize(); |
| 66 | return executor; |
| 67 | } |
| 68 | @Bean |
| 69 | public Executor taskExecutor_fileComponent_deleteInvalidFile() { |
| 70 | ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); |
| 71 | executor.setBeanName("taskExecutor_fileComponent_deleteInvalidFile"); |
| 72 | executor.setCorePoolSize(1);//核心线程池大小 |
| 73 |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…