-
Notifications
You must be signed in to change notification settings - Fork 202
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3356 from wangyu096/issue_3355
fix: 使用 spring 定时任务,线程池配置不合理导致定时任务阻塞 #3355
- Loading branch information
Showing
1 changed file
with
20 additions
and
0 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
...rvice-job-backup/src/main/java/com/tencent/bk/job/backup/config/SpringScheduleConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"))); | ||
} | ||
|
||
} |