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

Comparing jsr166/src/main/java/util/concurrent/ScheduledExecutor.java (file contents):
Revision 1.14 by tim, Fri Aug 8 20:05:07 2003 UTC vs.
Revision 1.15 by dl, Mon Aug 11 15:44:43 2003 UTC

# Line 98 | Line 98 | public class ScheduledExecutor extends T
98          }
99  
100          public int compareTo(Object other) {
101 +            if (other == this)
102 +                return 0;
103              DelayedTask x = (DelayedTask)other;
104              long diff = time - x.time;
105              if (diff < 0)
# Line 470 | Line 472 | public class ScheduledExecutor extends T
472      }
473  
474      /**
475 +     * Removes this task from internal queue if it is present, thus
476 +     * causing it not to be run if it has not already started.  This
477 +     * method may be useful as one part of a cancellation scheme.
478 +     *
479 +     * @param task the task to remove
480 +     * @return true if the task was removed
481 +     */
482 +    public boolean remove(Runnable task) {
483 +        if (task instanceof DelayedTask && getQueue().remove(task))
484 +            return true;
485 +
486 +        // The task might actually have been wrapped as a DelayedTask
487 +        // in execute(), in which case we need to maually traverse
488 +        // looking for it.
489 +
490 +        DelayedTask wrap = null;
491 +        Object[] entries = getQueue().toArray();
492 +        for (int i = 0; i < entries.length; ++i) {
493 +            DelayedTask t = (DelayedTask)entries[i];
494 +            Runnable r = t.getRunnable();
495 +            if (task.equals(r)) {
496 +                wrap = t;
497 +                break;
498 +            }
499 +        }
500 +        entries = null;
501 +        return wrap != null && getQueue().remove(wrap);
502 +    }
503 +
504 +    /**
505       * If executed task was periodic, cause the task for the next
506       * period to execute.
507       * @param r the task (assumed to be a DelayedTask)
# Line 484 | Line 516 | public class ScheduledExecutor extends T
516          if (next == null)
517              return;
518          try {
519 <            execute(next);
519 >            delayedExecute(next);
520          } catch(RejectedExecutionException ex) {
521              // lost race to detect shutdown; ignore
522          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines