问题描述
我正在尝试在 Spring 中安排一项每天午夜运行的任务.我遵循了 Spring 的 官方指南 并制作了如下调度程序类:>
I am trying to schedule a task in Spring which is to be run everyday at midnight. I followed the official guide from Spring and made the scheduler class as below:
@Component
public class OverduePaymentScheduler {
@Scheduled(cron = "0 0 0 * * *")
public void trackOverduePayments() {
System.out.println("Scheduled task running");
}
}
但是,当时钟到达凌晨 12 点时,任务不会运行.我从这个 链接的石英调度器文档中得到了 cron 表达式.
However the task does not run when the clock hits 12am. I got the cron expression from the documentation for quartz scheduler at this link.
如果我将 cron 表达式更改为*/10 * * * * *",则调度程序执行良好;每十秒运行一次.
The scheduler is executed fine if I change the cron expression to "*/10 * * * * *" which runs every ten seconds.
那我做错了什么?
推荐答案
我终于让它与这个 cron 表达式 0 0 0 * * *
一起工作,但我不得不在这样的调度程序类.@Scheduled(cron = "0 0 0 * * *",zone = "印度/马尔代夫")
I finally got it to work with this cron expression 0 0 0 * * *
but I had to set the time zone in the scheduler class like this.
@Scheduled(cron = "0 0 0 * * *",zone = "Indian/Maldives")
这篇关于Spring 调度 - 每天午夜的 Cron 表达式不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论