Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
5.4
Description
If you add a job with a CronSchedule that is to be run at only one time to the PeriodicExecutor, it will never stop executing. It also happens if you add one in the past:
The code below will run indefinitely now even though the cron was scheduled to run at midnight 1-Jan-2014:
periodicExecutor.addJob( new CronSchedule("0 0 0 1 1 ? 2014"), "Test", new Runnable() { @Override public void run() { System.out.println("Testing the run"); } } );
The problem is CronSchedule.nextExecution() returns 0 if there is no valid date in the future. This then leads PeriodicExecutorImpl to sleep for 0 seconds between runs.
My suggestion is around line 370 to do something like:
if (jobNextExecution == 0) { job.cancel(); } else if (jobNextExecution <= now) {
.....