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.40 by dl, Sun Feb 18 23:16:35 2007 UTC vs.
Revision 1.41 by dl, Tue Feb 20 00:11:20 2007 UTC

# Line 21 | Line 21 | import java.util.*;
21   * without any real-time guarantees about when, after they are
22   * enabled, they will commence. Tasks scheduled for exactly the same
23   * execution time are enabled in first-in-first-out (FIFO) order of
24 < * submission. Cancelled tasks are automatically removed from the
25 < * work queue.
24 > * submission. If {@link #setRemoveOnCancelPolicy} is set {@code true}
25 > * cancelled tasks are automatically removed from the work queue.
26   *
27   * <p>While this class inherits from {@link ThreadPoolExecutor}, a few
28   * of the inherited tuning methods are not useful for it. In
# Line 123 | Line 123 | public class ScheduledThreadPoolExecutor
123      private volatile boolean executeExistingDelayedTasksAfterShutdown = true;
124  
125      /**
126 +     * True if ScheduledFutureTask.cancel should remove from queue
127 +     */
128 +    private volatile boolean removeOnCancel = false;
129 +
130 +    /**
131       * Sequence number to break scheduling ties, and in turn to
132       * guarantee FIFO order among tied entries.
133       */
# Line 231 | Line 236 | public class ScheduledThreadPoolExecutor
236          }
237  
238          public boolean cancel(boolean mayInterruptIfRunning) {
239 <            remove(this); //  unconditionally remove
240 <            return super.cancel(mayInterruptIfRunning);
239 >            boolean cancelled = super.cancel(mayInterruptIfRunning);
240 >            if (cancelled && removeOnCancel && heapIndex >= 0)
241 >                remove(this);
242 >            return cancelled;
243          }
244  
245          /**
# Line 322 | Line 329 | public class ScheduledThreadPoolExecutor
329                  if (e instanceof RunnableScheduledFuture) {
330                      RunnableScheduledFuture<?> t =
331                          (RunnableScheduledFuture<?>)e;
332 <                    if ((t.isPeriodic() ? !keepPeriodic : !keepDelayed))
333 <                        t.cancel(false);
332 >                    if ((t.isPeriodic() ? !keepPeriodic : !keepDelayed) ||
333 >                        t.isCancelled()) { // also remove if already cancelled
334 >                        if (q.remove(t))
335 >                            t.cancel(false);
336 >                    }
337                  }
338              }
339          }
# Line 628 | Line 638 | public class ScheduledThreadPoolExecutor
638      }
639  
640      /**
641 +     * Sets the policy on whether to cancellation of a a task should
642 +     * remove it from the work queue.  This value is
643 +     * by default {@code false}.
644 +     *
645 +     * @param value if {@code true}, remove on cancellation, else don't.
646 +     * @see #getRemoveOnCancelPolicy
647 +     */
648 +    public void setRemoveOnCancelPolicy(boolean value) {
649 +        removeOnCancel = value;
650 +    }
651 +
652 +    /**
653 +     * Gets the policy on whether to cancellation of a a task should
654 +     * remove it from the work queue.
655 +     * This value is by default {@code false}.
656 +     *
657 +     * @return {@code true} if cancelled tasks are removed from the queue.
658 +     * @see #setRemoveOnCancelPolicy
659 +     */
660 +    public boolean getRemoveOnCancelPolicy() {
661 +        return removeOnCancel;
662 +    }
663 +
664 +    /**
665       * Initiates an orderly shutdown in which previously submitted
666       * tasks are executed, but no new tasks will be accepted.  If the
667       * {@code ExecuteExistingDelayedTasksAfterShutdownPolicy} has

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines