TrakcingScheduledExecutor CME fix take 2 Project: http://git-wip-us.apache.org/repos/asf/incubator-edgent/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-edgent/commit/bea8576b Tree: http://git-wip-us.apache.org/repos/asf/incubator-edgent/tree/bea8576b Diff: http://git-wip-us.apache.org/repos/asf/incubator-edgent/diff/bea8576b
Branch: refs/heads/develop Commit: bea8576b6eaa8c607263a1f633fffc7bf40b53da Parents: 786d934 Author: Dale LaBossiere <dlab...@us.ibm.com> Authored: Thu Oct 26 13:04:11 2017 -0400 Committer: Dale LaBossiere <dlab...@us.ibm.com> Committed: Thu Oct 26 13:04:11 2017 -0400 ---------------------------------------------------------------------- .../runtime/etiao/TrackingScheduledExecutor.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-edgent/blob/bea8576b/runtime/etiao/src/main/java/org/apache/edgent/runtime/etiao/TrackingScheduledExecutor.java ---------------------------------------------------------------------- diff --git a/runtime/etiao/src/main/java/org/apache/edgent/runtime/etiao/TrackingScheduledExecutor.java b/runtime/etiao/src/main/java/org/apache/edgent/runtime/etiao/TrackingScheduledExecutor.java index 478e419..fef4105 100644 --- a/runtime/etiao/src/main/java/org/apache/edgent/runtime/etiao/TrackingScheduledExecutor.java +++ b/runtime/etiao/src/main/java/org/apache/edgent/runtime/etiao/TrackingScheduledExecutor.java @@ -117,6 +117,7 @@ public final class TrackingScheduledExecutor extends ScheduledThreadPoolExecutor private int cancelAllAsyncTasks(boolean mayInterruptIfRunning) { int notCanceled = 0; + // follow the iterator access pattern doc'd by Collections:synchronizedSet() synchronized (asyncTasks) { // hmm have gotten CMEs here with testMultiTopologyPollWithError. // This seems to follow the required access pattern for synchronized collection iterator. @@ -126,10 +127,22 @@ public final class TrackingScheduledExecutor extends ScheduledThreadPoolExecutor // hasActiveTasks() - iterates while synchronized and can remove // removeTrack() - remove // Just to make things iron clad, synch the add and remove too - for (RunnableScheduledFuture<?> task : asyncTasks) { + // hmm... got another CME even after mods to the above. + // java.util.ConcurrentModificationException + // at java.util.HashMap$HashIterator.nextNode(HashMap.java:1437) + // at java.util.HashMap$KeyIterator.next(HashMap.java:1461) + // at: for (RunnableScheduledFuture<?> task : asyncTasks) +// for (RunnableScheduledFuture<?> task : asyncTasks) { +// if (!task.cancel(mayInterruptIfRunning)) +// notCanceled++; +// } + Iterator<RunnableScheduledFuture<?>> i = asyncTasks.iterator(); + while (i.hasNext()) { + RunnableScheduledFuture<?> task = i.next(); if (!task.cancel(mayInterruptIfRunning)) notCanceled++; } + // remove tasks which are done hasActiveTasks(); }