I want to schedule a task to run on last day of every month at 10:10 AM.
The cron expression is 0 10 10 L * ?
Now the problem is CronSequenceGener
There is another possible approach, depending on what you want to do:
import org.apache.commons.lang3.time.DateUtils;
@Scheduled(cron = "0 0 0 1 * ?") // runs on the first day of each month
public void doStuffOnFirstDayOfMonth() {
Date now = DateUtils.addDays(new Date(), -1); // "now" is now on the last day of the month
}
I use this to generate statistics for a month of data. The routine should run on the first day of the next month to be sure to capture all data of the full previous month.
While this does not answer the question in the sense of having a Cron Expression for the last day of the month, it still can be a solution for jobs which need to run for a full month and this as soon as possible after the month has come to an end.