Thanks, Pavel! I committed this to CVS, but am not planning to include it in this integration: (not sure if re-generating will invalidate my "Ready" status) (Having to cast to Future makes this more problematic, but in typical usages the user will know that the queue contains Futures)
--- src/main/java/util/concurrent/ThreadPoolExecutor.java 8 Dec 2020 20:33:21 -0000 1.195 +++ src/main/java/util/concurrent/ThreadPoolExecutor.java 9 Dec 2020 22:05:21 -0000 1.197 @@ -2066,10 +2066,12 @@ * <pre> {@code * new RejectedExecutionHandler() { * public void rejectedExecution(Runnable r, ThreadPoolExecutor e) { - * Future<?> dropped = e.getQueue().poll(); - * if (dropped != null) - * dropped.cancel(false); // also consider logging the failure - * e.execute(r); // retry + * Runnable dropped = e.getQueue().poll(); + * if (dropped instanceof Future<?>) { + * ((Future<?>)dropped).cancel(false); + * // also consider logging the failure + * } + * e.execute(r); // retry * }}}</pre> */ public static class DiscardOldestPolicy implements RejectedExecutionHandler { On Wed, Dec 9, 2020 at 10:46 AM Pavel Rappo <pra...@openjdk.java.net> wrote: > On Tue, 8 Dec 2020 21:15:48 GMT, Martin Buchholz <mar...@openjdk.org> > wrote: > > >> 8234131: Miscellaneous changes imported from jsr166 CVS 2020-12 > > > > Martin Buchholz has updated the pull request with a new target base due > to a merge or a rebase. The pull request now contains one commit: > > > > JDK-8234131 > > The changes to doc comments look good. > > Thanks for incorporating my earlier code snippet suggestions published on > [concurrency-interest]( > http://cs.oswego.edu/pipermail/concurrency-interest/2020-November/017264.html > )! > > src/java.base/share/classes/java/util/concurrent/ThreadPoolExecutor.java > line 2102: > > > 2100: * dropped.cancel(false); // also consider logging the > failure > > 2101: * e.execute(r); // retry > > 2102: * }}}</pre> > > I tried to reify that code snippet: > > $ cat MySnippet.java > import java.util.concurrent.Future; > import java.util.concurrent.RejectedExecutionHandler; > import java.util.concurrent.ThreadPoolExecutor; > > public class MySnippet { > public static void main(String[] args) { > new RejectedExecutionHandler() { > public void rejectedExecution(Runnable r, ThreadPoolExecutor > e) { > Future<?> dropped = e.getQueue().poll(); > if (dropped != null) > dropped.cancel(false); // also consider logging the > failure > e.execute(r); // retry > } > }; > } > } > $ javac MySnippet.java > MySnippet.java:9: error: incompatible types: Runnable cannot be converted > to Future<?> > Future<?> dropped = e.getQueue().poll(); > ^ > 1 error > $ > Separately, it seems that the `if` statement uses a 3-space indent which > is surprising to see in the JSR 166 code base. > > ------------- > > Marked as reviewed by prappo (Reviewer). > > PR: https://git.openjdk.java.net/jdk/pull/1647 >