Spring Scheduling - Cron expression for everyday at midnight not working?

Viewed 128936

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");
    }
}

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.

The scheduler is executed fine if I change the cron expression to "*/10 * * * * *" which runs every ten seconds.

So what am I doing wrong?

5 Answers

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")

You can use below format to satisfy your requirement:

0 0 23 * * *

Since the hours starts from 0 to 23 for Quartz configuration. You can refer this link for more information.

Related