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

Comparing jsr166/src/main/java/util/concurrent/ThreadPoolExecutor.java (file contents):
Revision 1.191 by jsr166, Thu Oct 17 01:51:38 2019 UTC vs.
Revision 1.192 by dl, Sun Feb 16 15:13:36 2020 UTC

# Line 192 | Line 192 | import java.util.concurrent.locks.Reentr
192   * simple feedback control mechanism that will slow down the rate that
193   * new tasks are submitted.
194   *
195 < * <li>In {@link ThreadPoolExecutor.DiscardPolicy}, a task that
196 < * cannot be executed is simply dropped.
195 > * <li>In {@link ThreadPoolExecutor.DiscardPolicy}, a task that cannot
196 > * be executed is simply dropped. This policy is designed only for
197 > * those rare cases in which task completion is never relied upon.
198   *
199   * <li>In {@link ThreadPoolExecutor.DiscardOldestPolicy}, if the
200   * executor is not shut down, the task at the head of the work queue
201   * is dropped, and then execution is retried (which can fail again,
202 < * causing this to be repeated.)
202 > * causing this to be repeated.) This policy is rarely acceptable.  In
203 > * nearly all cases, you should also cancel the task to cause an
204 > * exception in any component waiting for its completion, and/or log
205 > * the failure, as illustrated in {@link
206 > * ThreadPoolExecutor.DiscardOldestPolicy} documentation.
207   *
208   * </ol>
209   *
# Line 2052 | Line 2057 | public class ThreadPoolExecutor extends
2057      /**
2058       * A handler for rejected tasks that discards the oldest unhandled
2059       * request and then retries {@code execute}, unless the executor
2060 <     * is shut down, in which case the task is discarded.
2060 >     * is shut down, in which case the task is discarded. This policy is
2061 >     * rarely useful in cases where other threads may be waiting for
2062 >     * tasks to terminate, or failures must be recorded. Instead consider
2063 >     * using a handler of the form:
2064 >     * <pre> {@code
2065 >     * new RejectedExecutionHandler() {
2066 >     *   public void rejectedExecution(Runnable r, ThreadPoolExecutor e) {
2067 >     *     Future<?> dropped = e.getQueue().poll();
2068 >     *     if (dropped != null)
2069 >     *        dropped.cancel(false); // also consider logging the failure
2070 >     *     e.execute(r);             // retry
2071 >     * }}}</pre>
2072       */
2073      public static class DiscardOldestPolicy implements RejectedExecutionHandler {
2074          /**

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines