From a85572daaec0569f2ec1d441f7ebe2ba513cebba Mon Sep 17 00:00:00 2001 From: kohsuke Date: Fri, 4 Apr 2008 22:32:17 +0000 Subject: [PATCH] [fixed] if the timer is too busy, the old implementation can get behind the schedule. (issue #1512) In 1.203. git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@8278 71c3de6d-444a-0410-be80-ed276b4c234a --- .../main/java/hudson/triggers/Trigger.java | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/core/src/main/java/hudson/triggers/Trigger.java b/core/src/main/java/hudson/triggers/Trigger.java index 16ca5e2072..d4d8eecefe 100644 --- a/core/src/main/java/hudson/triggers/Trigger.java +++ b/core/src/main/java/hudson/triggers/Trigger.java @@ -26,6 +26,7 @@ import java.util.Collection; import java.util.Collections; import java.util.GregorianCalendar; import java.util.Timer; +import java.util.Date; import java.util.concurrent.Future; import java.util.logging.Level; import java.util.logging.Logger; @@ -135,17 +136,19 @@ public abstract class Trigger implements Describable> private final Calendar cal = new GregorianCalendar(); public void doRun() { - LOGGER.fine("cron checking "+cal.getTime().toLocaleString()); + while(new Date().getTime()-cal.getTimeInMillis()>1000) { + LOGGER.fine("cron checking "+cal.getTime().toLocaleString()); - try { - checkTriggers(cal); - } catch (Throwable e) { - LOGGER.log(Level.WARNING,"Cron thread throw an exception",e); - // bug in the code. Don't let the thread die. - e.printStackTrace(); + try { + checkTriggers(cal); + } catch (Throwable e) { + LOGGER.log(Level.WARNING,"Cron thread throw an exception",e); + // bug in the code. Don't let the thread die. + e.printStackTrace(); + } + + cal.add(Calendar.MINUTE,1); } - - cal.add(Calendar.MINUTE,1); } }