Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cron expression to run only on Monday

I am using quartz expressions to create a trigger that should execute only on Mondays and the day of month should not be 1.

I already know that 0 5 0 2-31 * MON expression doesn't work because Specifying both a day-of-week and a day-of-month parameter is not implemented. Is there any workaround for this issue? How can I achieve this?

To summarize, if 1st day of month is Monday, the above expression should not be executed but for other Mondays of the month, it should be executed.

like image 844
Suman Avatar asked Sep 05 '25 03:09

Suman


1 Answers

As support for specifying both a day-of-week AND a day-of-month parameter is not implemented, You can try with this:

@Scheduled(cron = "0 5 0 ? * MON")
private void doTask(){
    if(LocalDate.now().getDayOfMonth() != 1){
        //your code here
    }
}

You can also check and generate corn for quartz here.

like image 174
GolamMazid Sajib Avatar answered Sep 07 '25 23:09

GolamMazid Sajib