From 64ded2b256a3d762d780c319a27042c848d770ad Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Wed, 29 Dec 2010 18:32:19 +0300 Subject: [PATCH] wait for completion reliably --- .../src/com/intellij/concurrency/JobImpl.java | 29 +++++++++---------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/concurrency/JobImpl.java b/platform/platform-impl/src/com/intellij/concurrency/JobImpl.java index 3679b59b1f64..5102ade486f0 100644 --- a/platform/platform-impl/src/com/intellij/concurrency/JobImpl.java +++ b/platform/platform-impl/src/com/intellij/concurrency/JobImpl.java @@ -117,16 +117,15 @@ public class JobImpl implements Job { submitTasks(tasks, callerHasReadAccess, false); - while (!isDone() && JobSchedulerImpl.stealAndRunTask()) { - int i = 0; - } - // in case of imbalanced tasks one huge task can stuck running and we would fall to waitForTermination instead of doing useful work //// http://gafter.blogspot.com/2006/11/thread-pool-puzzler.html //for (PrioritizedFutureTask task : tasks) { // task.run(); //} // + while (!isDone() && JobSchedulerImpl.stealAndRunTask()) { + int i = 0; + } waitForTermination(); return null; @@ -135,8 +134,8 @@ public class JobImpl implements Job { public void waitForTermination() throws Throwable { Throwable ex = null; PrioritizedFutureTask[] tasks = getTasks(); - try { - for (PrioritizedFutureTask f : tasks) { + for (PrioritizedFutureTask f : tasks) { + try { // this loop is for workaround of mysterious bug // when sometimes future hangs inside parkAndCheckForInterrupt() during unbounded get() while(true) { @@ -152,16 +151,16 @@ public class JobImpl implements Job { } } } - } - catch (CancellationException ignore) { - // already cancelled - } - catch (ExecutionException e) { - cancel(); + catch (CancellationException ignore) { + // already cancelled + } + catch (ExecutionException e) { + cancel(); - Throwable cause = e.getCause(); - if (cause != null) { - ex = cause; + Throwable cause = e.getCause(); + if (cause != null) { + ex = cause; + } } }