...
|
...
|
@@ -2,20 +2,32 @@ package com.mass.config; |
2
|
2
|
|
3
|
3
|
import org.springframework.context.annotation.Bean;
|
4
|
4
|
import org.springframework.context.annotation.Configuration;
|
|
5
|
+import org.springframework.scheduling.TaskScheduler;
|
5
|
6
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
6
|
|
-import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
|
7
|
+import org.springframework.scheduling.annotation.SchedulingConfigurer;
|
|
8
|
+import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
|
|
9
|
+import org.springframework.scheduling.config.ScheduledTaskRegistrar;
|
|
10
|
+
|
|
11
|
+import java.util.concurrent.ThreadPoolExecutor;
|
|
12
|
+
|
7
|
13
|
|
8
|
14
|
@Configuration
|
9
|
|
-@EnableScheduling
|
10
|
|
-public class TaskExecutorConfig {
|
|
15
|
+public class TaskExecutorConfig implements SchedulingConfigurer {
|
11
|
16
|
@Bean
|
12
|
|
- public ThreadPoolTaskExecutor taskExecutor() {
|
13
|
|
- ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
|
14
|
|
- executor.setCorePoolSize(10);
|
15
|
|
- executor.setMaxPoolSize(50);
|
16
|
|
- executor.setQueueCapacity(1000);
|
17
|
|
- executor.setKeepAliveSeconds(60);
|
18
|
|
- executor.setThreadNamePrefix("task-executor-");
|
|
17
|
+ public TaskScheduler taskScheduler() {
|
|
18
|
+ ThreadPoolTaskScheduler executor = new ThreadPoolTaskScheduler();
|
|
19
|
+ executor.setPoolSize(10);
|
|
20
|
+ executor.setThreadNamePrefix("task-thread");
|
|
21
|
+ executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
|
|
22
|
+ executor.initialize();
|
19
|
23
|
return executor;
|
20
|
24
|
}
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+ @Override
|
|
28
|
+ public void configureTasks(ScheduledTaskRegistrar scheduledTaskRegistrar) {
|
|
29
|
+ scheduledTaskRegistrar.setTaskScheduler(taskScheduler());
|
|
30
|
+ }
|
|
31
|
+
|
|
32
|
+
|
21
|
33
|
} |
...
|
...
|
|