MCPcopy Create free account
hub / github.com/diyhi/bbs / AsyncConfig

Class AsyncConfig

src/main/java/cms/config/AsyncConfig.java:16–78  ·  view source on GitHub ↗

多线程执行定时任务 @author Gao

Source from the content-addressed store, hash-verified

14 *
15 */
16@Configuration
17@EnableAsync// 开启异步事件的支持
18public 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

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…