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

て烟熏妆下的殇ゞ 提交于 2019-11-27 08:13:25

问题


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.


回答1:


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



回答2:


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.



来源:https://stackoverflow.com/questions/36641783/quartz-cron-expression-for-once-in-a-two-week-on-particular-day

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!