This commit is contained in:
2024-01-22 11:28:30 +08:00
parent 7ee67ca76f
commit 6fdd7965e5

View File

@@ -22,10 +22,10 @@ import org.springframework.stereotype.Service;
public class HutoolTimerExeServiceImpl implements TimerExeService { public class HutoolTimerExeServiceImpl implements TimerExeService {
private static final Log log = Log.get(); private static final Log log = Log.get();
@Value("${runTake.maxRetryCount}") // @Value("${runTake.maxRetryCount}")
private Integer maxRetryCount; // private Integer maxRetryCount;
@Value("${runTake.delayTime}") // @Value("${runTake.delayTime}")
private Integer delayTime; // private Integer delayTime;
@Override @Override
public void startTimer(String taskId, String cron, String className) { public void startTimer(String taskId, String cron, String className) {
@@ -63,7 +63,7 @@ public class HutoolTimerExeServiceImpl implements TimerExeService {
public void runTaskWithRetryAndDelay(TimerTaskRunner timerTaskRunner) throws InterruptedException { public void runTaskWithRetryAndDelay(TimerTaskRunner timerTaskRunner) throws InterruptedException {
int retryCount = 0; // 重试次数计数器 int retryCount = 0; // 重试次数计数器
while (retryCount < maxRetryCount) { while (retryCount < 10) {
try { try {
System.out.println("重试机制:"+(retryCount+1)); System.out.println("重试机制:"+(retryCount+1));
timerTaskRunner.action(); timerTaskRunner.action();
@@ -71,10 +71,10 @@ public class HutoolTimerExeServiceImpl implements TimerExeService {
} catch (Exception e) { } catch (Exception e) {
// 处理异常 // 处理异常
retryCount++; // 增加重试次数 retryCount++; // 增加重试次数
Thread.sleep(delayTime); // 等待一段时间 Thread.sleep(25000); // 等待一段时间
} }
} }
if (retryCount >= maxRetryCount) { if (retryCount >= 10) {
// 达到最大重试次数,终止任务 // 达到最大重试次数,终止任务
return; return;
} }