Reputation: 529
I am trying to figure out the cron expression for executing once in 5weeks, that is 35 days from a particular day. I couldnt find a solution directly using quartz.
Can someone advise?
Upvotes: 0
Views: 1266
Reputation: 1880
As noted by Puchacz, cron expressions are not suited for these types of schedules. You should use CalendarIntervalTrigger with the week repeat interval unit and 5 for the repeat interval. Code-wise there is hardly any difference between using cron and calendar interval triggers in Quartz.
See below for an example schedule of a CalendarIntervalTrigger that starts firing at midnight, November 1st, 2017. By changing the start time you can adjust the time of day when you want your job to be fired.
Upvotes: 0
Reputation: 608
There is no direct solution for this.
Following solution will help you:
Create a job in quartz with below cron, make *_JOB_DETAILS table job_data column data as milliseconds of next fire time.
It will run every week(You can make this every day also).
0 0 12 ? * MON *
Quartz job will call java application for every Week(Monday 12:00 AM). On your business logic check job_data with current time. If it exceeds execute your logic else do nothing. After executing of your logic update the JOB_DATA with below time, then next trigger time will store in job_data.
Calendar c=new GregorianCalendar();
c.add(Calendar.DATE, 35);
c.getTime();//add this data
You will get expected result.
Upvotes: 0
Reputation: 2105
Pointless to write such expression (it won't work), Try to use http://www.quartz-scheduler.org/documentation/quartz-2.x/tutorials/tutorial-lesson-05.html rather than cron expression which is just not suitable for this type of job.
Upvotes: 0