2 changed files with 48 additions and 11 deletions
@ -0,0 +1,35 @@ |
|||||||
|
package com.biutag.outer.config; |
||||||
|
|
||||||
|
import org.springframework.context.annotation.Bean; |
||||||
|
import org.springframework.context.annotation.Configuration; |
||||||
|
import org.springframework.scheduling.annotation.EnableScheduling; |
||||||
|
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; |
||||||
|
|
||||||
|
import java.util.concurrent.ThreadPoolExecutor; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author wxc |
||||||
|
* @date 2025/9/22 |
||||||
|
*/ |
||||||
|
@Configuration |
||||||
|
@EnableScheduling |
||||||
|
public class SchedulerConfig { |
||||||
|
|
||||||
|
@Bean |
||||||
|
public ThreadPoolTaskScheduler taskScheduler() { |
||||||
|
ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler(); |
||||||
|
// 设置线程池大小
|
||||||
|
scheduler.setPoolSize(10); |
||||||
|
// 设置线程名前缀
|
||||||
|
scheduler.setThreadNamePrefix("scheduled-task-"); |
||||||
|
// 设置线程池关闭时等待所有任务完成
|
||||||
|
scheduler.setWaitForTasksToCompleteOnShutdown(true); |
||||||
|
// 设置等待终止时间(单位:秒)
|
||||||
|
scheduler.setAwaitTerminationSeconds(60); |
||||||
|
// 设置拒绝策略
|
||||||
|
scheduler.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy()); |
||||||
|
// 初始化线程池
|
||||||
|
scheduler.initialize(); |
||||||
|
return scheduler; |
||||||
|
} |
||||||
|
} |
||||||
Loading…
Reference in new issue