ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/main/java/util/concurrent/ScheduledThreadPoolExecutor.java
(Generate patch)

Comparing jsr166/src/main/java/util/concurrent/ScheduledThreadPoolExecutor.java (file contents):
Revision 1.15 by dl, Mon Jan 19 15:49:02 2004 UTC vs.
Revision 1.16 by dl, Wed Jan 21 01:47:00 2004 UTC

# Line 68 | Line 68 | public class ScheduledThreadPoolExecutor
68          private final long sequenceNumber;
69          /** The time the task is enabled to execute in nanoTime units */
70          private long time;
71 <        /** The delay following next time, or <= 0 if non-periodic */
71 >        /**
72 >         * Period in nanoseconds for repeating tasks.  A positive
73 >         * value indicates fixed-rate execution.  A negative value
74 >         * indicates fixed-delay execution.  A value of 0 indicates a
75 >         * non-repeating task.
76 >         */
77          private final long period;
73        /** true if at fixed rate; false if fixed delay */
74        private final boolean rateBased;
78  
79          /**
80           * Creates a one-shot action with given nanoTime-based trigger time
# Line 80 | Line 83 | public class ScheduledThreadPoolExecutor
83              super(r, result);
84              this.time = ns;
85              this.period = 0;
83            rateBased = false;
86              this.sequenceNumber = sequencer.getAndIncrement();
87          }
88  
89          /**
90           * Creates a periodic action with given nano time and period
91           */
92 <        ScheduledFutureTask(Runnable r, V result, long ns,  long period, boolean rateBased) {
92 >        ScheduledFutureTask(Runnable r, V result, long ns,  long period) {
93              super(r, result);
94              this.time = ns;
95              this.period = period;
94            this.rateBased = rateBased;
96              this.sequenceNumber = sequencer.getAndIncrement();
97          }
98  
# Line 102 | Line 103 | public class ScheduledThreadPoolExecutor
103              super(callable);
104              this.time = ns;
105              this.period = 0;
105            rateBased = false;
106              this.sequenceNumber = sequencer.getAndIncrement();
107          }
108  
# Line 131 | Line 131 | public class ScheduledThreadPoolExecutor
131           * @return true if periodic
132           */
133          boolean isPeriodic() {
134 <            return period > 0;
134 >            return period != 0;
135          }
136  
137          /**
# Line 153 | Line 153 | public class ScheduledThreadPoolExecutor
153              if (ok && (!down ||
154                         (getContinueExistingPeriodicTasksAfterShutdownPolicy() &&
155                          !isTerminating()))) {
156 <                time = period + (rateBased ? time : now());
156 >                long p = period;
157 >                if (p > 0)
158 >                    time += p;
159 >                else
160 >                    time = now() - p;
161                  ScheduledThreadPoolExecutor.super.getQueue().add(this);
162              }
163              // This might have been the final executed delayed
# Line 296 | Line 300 | public class ScheduledThreadPoolExecutor
300                                             TimeUnit unit) {
301          if (callable == null || unit == null)
302              throw new NullPointerException();
303 +        if (delay < 0) delay = 0;
304          long triggerTime = now() + unit.toNanos(delay);
305          ScheduledFutureTask<V> t =
306              new ScheduledFutureTask<V>(callable, triggerTime);
# Line 311 | Line 316 | public class ScheduledThreadPoolExecutor
316              throw new NullPointerException();
317          if (period <= 0)
318              throw new IllegalArgumentException();
319 +        if (initialDelay < 0) initialDelay = 0;
320          long triggerTime = now() + unit.toNanos(initialDelay);
321          ScheduledFutureTask<?> t =
322              new ScheduledFutureTask<Object>(command,
323                                              null,
324                                              triggerTime,
325 <                                            unit.toNanos(period),
320 <                                            true);
325 >                                            unit.toNanos(period));
326          delayedExecute(t);
327          return t;
328      }
# Line 330 | Line 335 | public class ScheduledThreadPoolExecutor
335              throw new NullPointerException();
336          if (delay <= 0)
337              throw new IllegalArgumentException();
338 +        if (initialDelay < 0) initialDelay = 0;
339          long triggerTime = now() + unit.toNanos(initialDelay);
340          ScheduledFutureTask<?> t =
341              new ScheduledFutureTask<Boolean>(command,
342                                               null,
343                                               triggerTime,
344 <                                             unit.toNanos(delay),
339 <                                             false);
344 >                                             unit.toNanos(-delay));
345          delayedExecute(t);
346          return t;
347      }
# Line 384 | Line 389 | public class ScheduledThreadPoolExecutor
389       * <tt>false</tt> when already shutdown. This value is by default
390       * false.
391       * @param value if true, continue after shutdown, else don't.
392 +     * @see #getExecuteExistingDelayedTasksAfterShutdownPolicy
393       */
394      public void setContinueExistingPeriodicTasksAfterShutdownPolicy(boolean value) {
395          continueExistingPeriodicTasksAfterShutdown = value;
# Line 399 | Line 405 | public class ScheduledThreadPoolExecutor
405       * to <tt>false</tt> when already shutdown. This value is by
406       * default false.
407       * @return true if will continue after shutdown.
408 +     * @see #setContinueExistingPeriodicTasksAfterShutdownPolicy
409       */
410      public boolean getContinueExistingPeriodicTasksAfterShutdownPolicy() {
411          return continueExistingPeriodicTasksAfterShutdown;
# Line 412 | Line 419 | public class ScheduledThreadPoolExecutor
419       * <tt>false</tt> when already shutdown. This value is by default
420       * true.
421       * @param value if true, execute after shutdown, else don't.
422 +     * @see #getExecuteExistingDelayedTasksAfterShutdownPolicy
423       */
424      public void setExecuteExistingDelayedTasksAfterShutdownPolicy(boolean value) {
425          executeExistingDelayedTasksAfterShutdown = value;
# Line 427 | Line 435 | public class ScheduledThreadPoolExecutor
435       * <tt>false</tt> when already shutdown. This value is by default
436       * true.
437       * @return true if will execute after shutdown.
438 +     * @see #setExecuteExistingDelayedTasksAfterShutdownPolicy
439       */
440      public boolean getExecuteExistingDelayedTasksAfterShutdownPolicy() {
441          return executeExistingDelayedTasksAfterShutdown;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines