Skip to content

Commit 1b3b646

Browse files
committed
feat: 配置定时线程池线程数、关闭前等待时间
1 parent f8e912e commit 1b3b646

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

framework/src/main/java/com/github/cadecode/uniboot/framework/config/ThreadPoolConfig.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
import lombok.RequiredArgsConstructor;
44
import lombok.extern.slf4j.Slf4j;
5+
import org.dromara.dynamictp.core.thread.DtpExecutor;
56
import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler;
67
import org.springframework.context.annotation.Bean;
78
import org.springframework.context.annotation.Configuration;
8-
import org.springframework.core.task.AsyncTaskExecutor;
99
import org.springframework.scheduling.annotation.AsyncConfigurer;
1010
import org.springframework.scheduling.annotation.EnableAsync;
1111
import org.springframework.scheduling.annotation.EnableScheduling;
@@ -28,18 +28,21 @@
2828
@Configuration
2929
public class ThreadPoolConfig {
3030

31-
private final AsyncTaskExecutor asyncExecutor;
31+
private final DtpExecutor asyncExecutor;
3232

3333
/**
3434
* Spring 定时任务线程池
3535
*/
3636
@Bean(name = "taskScheduler", destroyMethod = "shutdown")
3737
public ThreadPoolTaskScheduler taskScheduler() {
3838
ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
39-
scheduler.setPoolSize(6);
39+
scheduler.setPoolSize(Runtime.getRuntime().availableProcessors());
4040
scheduler.setThreadNamePrefix("taskScheduler-");
4141
scheduler.setWaitForTasksToCompleteOnShutdown(true);
42-
scheduler.setAwaitTerminationSeconds(5);
42+
scheduler.setAwaitTerminationSeconds(300);
43+
scheduler.setErrorHandler(throwable -> {
44+
log.error("Scheduled task execute fail,", throwable);
45+
});
4346
return scheduler;
4447
}
4548

0 commit comments

Comments
 (0)