admin管理员组

文章数量:1122832

Is it possible to set Spring Scheduler to run every month when there are six days left until the end of the month ?

If so, what would be the CRON expression for this to happen ?

Is it possible to set Spring Scheduler to run every month when there are six days left until the end of the month ?

If so, what would be the CRON expression for this to happen ?

Share Improve this question edited Nov 22, 2024 at 9:34 Francesco Poli 1,2748 silver badges16 bronze badges asked Nov 22, 2024 at 8:48 MykoliuxMykoliux 1134 silver badges7 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 4

Since Spring 5.3, CronExpression supports L as the last day of the month. So you can use this kind of expression for your case:

0 0 0 L-6 * *

This will run at midnight 6 days before the end of month, accordingly to https://crontab.cronhub.io/

Check also this pages:

https://spring.io/blog/2020/11/10/new-in-spring-5-3-improved-cron-expressions

https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/scheduling/support/CronExpression.html

本文标签: