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

0

Issue

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?

Solution

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

Answered By – Charlie

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave A Reply

Your email address will not be published.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More