From 6d4978f6522813cc0a2ca6ac5abef3d65da381d0 Mon Sep 17 00:00:00 2001 From: hns Date: Wed, 20 Jul 2005 13:49:37 +0000 Subject: [PATCH] * Fix bug 435, cron jobs are run even if the function name is not defined * Fix a bug that caused the scheduler thread to awaken twice in immedate succession because of imprecise timing in Thread.sleep() --- src/helma/util/CronJob.java | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/helma/util/CronJob.java b/src/helma/util/CronJob.java index 87b83f98..e381eebe 100644 --- a/src/helma/util/CronJob.java +++ b/src/helma/util/CronJob.java @@ -193,6 +193,8 @@ public class CronJob { StringTokenizer st = new StringTokenizer (key.trim(), "."); st.nextElement (); String jobName = st.nextToken (); + if (jobName == null || jobName.equals("")) + continue; String jobSpec = st.nextToken (); if (jobSpec==null || jobSpec.equals("")) // might happen with cron.testname. = XXX continue; @@ -222,7 +224,16 @@ public class CronJob { } catch (NoSuchElementException nsee) { } } - List jobVec = new ArrayList (jobs.values ()); + Iterator it = jobs.values().iterator(); + while (it.hasNext()) { + CronJob job = (CronJob) it.next(); + if (job.getFunction() == null) { + System.err.println("DROPPING CRON JOB " + job); + it.remove(); + } + } + List jobVec = new ArrayList (jobs.values()); + System.err.println("GOT CRON JOB LIST: " + jobVec); return sort (jobVec); } @@ -412,7 +423,13 @@ public class CronJob { public static long millisToNextFullMinute () { long now = System.currentTimeMillis(); long millisAfterMinute = (now % 60000); - return (60000 - millisAfterMinute); + // We return the interval to one second past the next full minute + // to avoid the case where the scheduler wakes up slightly before the minute + // and finishes so fast that the next call to this method returns the + // interval to the same minute instead of the next one. This happened + // sometimes with the old code and caused the scheduler to run twice in + // immediate succession. + return (61000 - millisAfterMinute); } /**