Quartz - CronTrigger - Problem when executing a job monthly
807588Nov 3 2008 — edited Jan 20 2009Hi everyone:
I've been looking around and trying to do it with some methods but I can't find the solution. The problem is: I have to give the user the option of selecting when execute the job. One option is executing it monthly and they can set the day of the month. Here is the problem, if they select a date after 28 I get a problem when february comes. What I want to do is that if they select the date to execute the job in the 31th for example, in the months that don't have 31 days, the job would be executed on the 30th of those months. That's no problem because I can set there a conditional clause and if date==31 set in the cron expression 'L' for the day of the month (execute the last day of the month), but it does not work for february, 'cause if they select the day 29th, it won't be executed in february.
I've guessed that the only solution for this is editing the cron once we are in the execution of the job, and if day of execution is greater than 28 and the current month is january, set the nextfiredtime to the last day of february but it doesn't work with
job.getTrigger().getNextFireTime().setTime(xxx);
or
job.getNextFireTime().setTime(xxx)
Do you know anything I can do to manage this problem? I would appreciate it very much
Thank you very muc for your attention
Kind regards