Santosh
Santosh

Reputation: 202

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.

Upvotes: 2

Views: 3126

Answers (2)

Rob Audenaerde
Rob Audenaerde

Reputation: 20029

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();

Upvotes: 3

dquijada
dquijada

Reputation: 1699

This is a limitation of cron-like expressions. The best solution that comes to my mind is to create two triggers for that job, instead of trying to use it only with the cron expression.

Upvotes: 0

Related Questions