AsyncConfig.java
2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package com.batch.config;
import java.util.concurrent.Executor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
@Configuration
@EnableAsync
public class AsyncConfig {
@Value("${thread.comm.count}")
Integer iCommAsyncThreadCount;
@Value("${thread.ext.count}")
Integer iExtAsyncThreadCount;
@Value("${thread.ai.count}")
Integer iAiAsyncThreadCount;
@Bean(name = "commAsync")
public Executor commAsyncExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(iCommAsyncThreadCount);
executor.setMaxPoolSize(iCommAsyncThreadCount);
executor.setQueueCapacity(1000);
executor.setKeepAliveSeconds(15);
executor.setAllowCoreThreadTimeOut(true);
executor.setWaitForTasksToCompleteOnShutdown(true);
executor.setThreadNamePrefix("commAsync-processor-");
executor.initialize();
return executor;
}
@Bean(name = "extAsync")
public Executor extAsyncExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(iExtAsyncThreadCount);
executor.setMaxPoolSize(iExtAsyncThreadCount);
executor.setQueueCapacity(1000);
executor.setKeepAliveSeconds(15);
executor.setAllowCoreThreadTimeOut(true);
executor.setWaitForTasksToCompleteOnShutdown(true);
executor.setThreadNamePrefix("extAsync-processor-");
executor.initialize();
return executor;
}
@Bean(name = "aiAsync")
public Executor aiAsyncExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(iAiAsyncThreadCount);
executor.setMaxPoolSize(iAiAsyncThreadCount);
executor.setQueueCapacity(1000);
executor.setKeepAliveSeconds(15);
executor.setAllowCoreThreadTimeOut(true);
executor.setWaitForTasksToCompleteOnShutdown(true);
executor.setThreadNamePrefix("aiAsync-processor-");
executor.initialize();
return executor;
}
}