【发布时间】:2021-12-24 18:43:28
【问题描述】:
我正在处理 Spring Batch 应用程序,我必须以这种方式安排工作:我的工作必须在每个星期日晚上 01:30 am 运行。
查看 Spring 文档,这里:https://spring.io/blog/2020/11/10/new-in-spring-5-3-improved-cron-expressions
它显示了这个图表:
┌───────────── second (0-59)
│ ┌───────────── minute (0 - 59)
│ │ ┌───────────── hour (0 - 23)
│ │ │ ┌───────────── day of the month (1 - 31)
│ │ │ │ ┌───────────── month (1 - 12) (or JAN-DEC)
│ │ │ │ │ ┌───────────── day of the week (0 - 7)
│ │ │ │ │ │ (or MON-SUN -- 0 or 7 is Sunday)
│ │ │ │ │ │
* * * * * *
所以我正在考虑对定义我的作业以这种方式运行的方法进行注释:
@Scheduled(cron = "0 30 01 * * 7")
public void runSpringBatchExampleJob() throws JobParametersInvalidException, JobExecutionAlreadyRunningException, JobRestartException, JobInstanceAlreadyCompleteException {
LOGGER.info("Spring Batch example job was started");
List<NotaryDistrict> notaryDistrictsList = new ArrayList<NotaryDistrict>();
executionContext.put("notaryDistrictsList", notaryDistrictsList);
jobLauncher.run(job, newExecution());
LOGGER.info("Spring Batch example job was stopped");
}
正确吗?每周日(第 7 天)上午 1:30 运行?
【问题讨论】:
-
根据文档看起来没问题...
-
唯一我不确定的是小时数应该是 01 还是 1
-
他们确实举了早上 6 点的例子,也就是
0 0 6,19 * * * 6:00 AM and 7:00 PM every day,所以我认为你应该这样做@Scheduled(cron = "0 30 1 * * 7")
标签: java spring spring-boot spring-batch