Search code examples
springspring-bootcronschedule

This cron 0 0 0 30 * * *. Does it run in February? Spring schedule


I have a cron with this expresion @Scheduled(cron = "0 0 0 30 * * *").

Does it run when February is finishing?

Thanks for your help

My solution: Expresion February

cron = "0 0 0 28 2 *"

Rest of the year

cron = "0 0 0 30 1,3,4,5,6,7,8,9,10,11,12 *"

Solution

  • Short answer: NO

    First, check out this website, it will calculate up the next 500 dates that your cron expression covers. Running your cron expression doesn´t cover february (I changed a little because it was invalid at first).

    Second, it might be easier to execute this task on the 1st of every month. Check if possible in your business logic.

    Third, if you need it on the last day of month, check this post. First answer pretty much covers every possible month.

    Last, if you really need it on every 30 except february, try this to cover february and your other cron to the rest of the year:

    0 0 0 28 2 ? *