我已经编写了一个Spring Boot应用程序,其中我已经启用了Spring Batch Scheduling和Retriable,如下所示:
@SpringBootApplication
@EnableBatchProcessing
@EnableScheduling
@EnableRetry
public class FilldashboardApp {
}我定义了一个控制器,如下:
@Component
public class JobRunnerStats {
@Scheduled(cron = "0 0/2 * ? * *")
@Retryable(maxAttempts = 10, backoff = @Backoff(delay = 1000))
protected JobExecution runJob() throws JobExecutionAlreadyRunningException, JobRestartException, JobInstanceAlreadyCompleteException, JobParametersInvalidException {
JobParameters jobParameters = null;
if (this.jobParameters == null) {
jobParameters = buildJobParameters(null);
} else {
jobParameters = this.jobParameters;
this.jobParameters = null;
}
return simpleJobLauncher.run(this.jobStats, jobParameters);
}
}2分钟后,由于指定的cron表达式启动了作业,所以在它的第一步中,我将在异常中发送它,因此在作业执行和步骤中,我已经跟踪了FAILED状态。
因此,正如@Retryable注释所解释的那样,我等待在1秒(延迟= 1000微秒)之后调用该作业,但是该方法中的下一次访问是在2分钟之后(因此,当cron表达式匹配时)
我不知道我的错在哪里
发布于 2021-09-24 15:41:44
在Spring重试上查看this issue。你遇到的问题很可能是一个只在4.3.14,5.0.3版本中修复的Spring bug (SPR-16196)。我在没有使用Spring Batch的情况下测试了你的代码片段,它工作得很好。
@Component
public class TestComponent {
Logger logger = LoggerFactory.getLogger(TestApplication.class);
@Retryable(maxAttempts = 10, backoff = @Backoff(delay = 1000))
@Scheduled(cron = "0 0/2 * ? * *")
public void foo() {
logger.info("foo");
throw new RuntimeException("runtime");
}
}发布于 2021-09-24 14:56:36
您是否尝试过将所有预期的异常都包含为可重试的参数?
@Retryable(maxAttempts = 10, backoff = @Backoff(delay = 1000),value={JobExecutionAlreadyRunningException.class})我读了一些教程,我不确定当未指定异常(预期)时,可重试的行为如何
https://stackoverflow.com/questions/69316689
复制相似问题