From c074f73bcb782527773356995d3635f32116d358 Mon Sep 17 00:00:00 2001 From: ray Date: Tue, 20 May 2008 19:34:23 +0000 Subject: [PATCH] Patch from Charlie Groves to expose Timer's ability to schedule at a fixed delay. We haven't needed this before now. git-svn-id: https://samskivert.googlecode.com/svn/trunk@2307 6335cc39-0255-0410-8fd6-9bcaacd3b74c --- src/java/com/samskivert/util/Interval.java | 26 ++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/src/java/com/samskivert/util/Interval.java b/src/java/com/samskivert/util/Interval.java index 8f24e6fe..97615ba3 100644 --- a/src/java/com/samskivert/util/Interval.java +++ b/src/java/com/samskivert/util/Interval.java @@ -88,8 +88,8 @@ public abstract class Interval } /** - * Schedule the interval to execute repeatedly, with the same delay. Supersedes any previous - * schedule that this Interval may have had. + * Schedule the interval to execute repeatedly with fixed-rate scheduling between repeats, + * with the same delay. Supersedes any previous schedule that this Interval may have had. */ public final void schedule (long delay, boolean repeat) { @@ -98,9 +98,25 @@ public abstract class Interval /** * Schedule the interval to execute repeatedly with the specified initial delay and repeat - * delay. Supersedes any previous schedule that this Interval may have had. + * delay with fixed-rate scheduling between repeats. Supersedes any previous schedule that + * this Interval may have had. */ public final void schedule (long initialDelay, long repeatDelay) + { + schedule(initialDelay, repeatDelay, true); + } + + /** + * Schedule the interval to execute repeatedly with the specified initial delay and repeat + * delay. Supersedes any previous schedule that this Interval may have had. + * + * @param fixedRate - if true, this interval schedules repeated expirations using + * {@link Timer#scheduleAtFixedRate(TimerTask, long, long)} ensuring that the number of + * expired calls will match the amount of time elapsed. If false, it uses + * {@link Timer#schedule(TimerTask, long, long)} which ensures that there will be close to + * repeateDelay milliseconds between expirations. + */ + public final void schedule (long initialDelay, long repeatDelay, boolean fixedRate) { cancel(); IntervalTask task = new IntervalTask(this); @@ -111,8 +127,10 @@ public abstract class Interval try { if (repeatDelay == 0L) { _timer.schedule(task, initialDelay); - } else { + } else if (fixedRate) { _timer.scheduleAtFixedRate(task, initialDelay, repeatDelay); + } else { + _timer.schedule(task, initialDelay, repeatDelay); } return;