Search code examples
javaquartz-scheduler

Quartz cron expression for Once in a two week on particular day


I am trying to create the Quartz cron expression which runs on every 2 week on given day

e.g.

Once in a every two week on Monday

and using the following expression

0 0 6 ? * 1#2,1#4

but somehow I am getting following error

Support for specifying multiple "nth" days is not implemented.


Solution

  • This is something that is also very hard with the regular cron jobs, I think it cannot be achieved in a 'normal' cron expression.

    You could skip cron altogether and use the Trigger That Executes Every 2 Weeks

    trigger = newTrigger()
    .withIdentity("trigger3", "group1")
    .startAt(tomorrowAt(15, 0, 0)  // 15:00:00 tomorrow
    .withSchedule(calendarIntervalSchedule()
            .withIntervalInWeeks(2)) // interval is set in calendar weeks
    .build();