Skip to content

Commit

Permalink
Merge pull request #3356 from wangyu096/issue_3355
Browse files Browse the repository at this point in the history
fix: 使用 spring 定时任务,线程池配置不合理导致定时任务阻塞 #3355
  • Loading branch information
jsonwan authored Dec 25, 2024
2 parents 52922c3 + 9162917 commit 923d943
Showing 1 changed file with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.tencent.bk.job.backup.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.SchedulingConfigurer;
import org.springframework.scheduling.config.ScheduledTaskRegistrar;

import java.util.concurrent.ScheduledThreadPoolExecutor;

@Configuration
@Slf4j
public class SpringScheduleConfig implements SchedulingConfigurer {
public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
log.info("Configure spring cron task scheduler");
//设定一个长度5的定时任务线程池
taskRegistrar.setScheduler(new ScheduledThreadPoolExecutor(5, (r, executor) -> log.error(
"ScheduledThreadPoolExecutor rejected a runnable")));
}

}

0 comments on commit 923d943

Please sign in to comment.