|
2 | 2 |
|
3 | 3 | import lombok.RequiredArgsConstructor; |
4 | 4 | import lombok.extern.slf4j.Slf4j; |
| 5 | +import org.dromara.dynamictp.core.thread.DtpExecutor; |
5 | 6 | import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler; |
6 | 7 | import org.springframework.context.annotation.Bean; |
7 | 8 | import org.springframework.context.annotation.Configuration; |
8 | | -import org.springframework.core.task.AsyncTaskExecutor; |
9 | 9 | import org.springframework.scheduling.annotation.AsyncConfigurer; |
10 | 10 | import org.springframework.scheduling.annotation.EnableAsync; |
11 | 11 | import org.springframework.scheduling.annotation.EnableScheduling; |
|
28 | 28 | @Configuration |
29 | 29 | public class ThreadPoolConfig { |
30 | 30 |
|
31 | | - private final AsyncTaskExecutor asyncExecutor; |
| 31 | + private final DtpExecutor asyncExecutor; |
32 | 32 |
|
33 | 33 | /** |
34 | 34 | * Spring 定时任务线程池 |
35 | 35 | */ |
36 | 36 | @Bean(name = "taskScheduler", destroyMethod = "shutdown") |
37 | 37 | public ThreadPoolTaskScheduler taskScheduler() { |
38 | 38 | ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler(); |
39 | | - scheduler.setPoolSize(6); |
| 39 | + scheduler.setPoolSize(Runtime.getRuntime().availableProcessors()); |
40 | 40 | scheduler.setThreadNamePrefix("taskScheduler-"); |
41 | 41 | scheduler.setWaitForTasksToCompleteOnShutdown(true); |
42 | | - scheduler.setAwaitTerminationSeconds(5); |
| 42 | + scheduler.setAwaitTerminationSeconds(300); |
| 43 | + scheduler.setErrorHandler(throwable -> { |
| 44 | + log.error("Scheduled task execute fail,", throwable); |
| 45 | + }); |
43 | 46 | return scheduler; |
44 | 47 | } |
45 | 48 |
|
|
0 commit comments