From 4323fcde8fa4312d5f12a474980cc29ed071f794 Mon Sep 17 00:00:00 2001 From: Dennis Ushakov Date: Thu, 8 Jul 2010 20:54:16 +0400 Subject: [PATCH] simplified time-limited execution mode, probably fixes timeout problems --- .../intellij/execution/ExecutionHelper.java | 39 +++---------------- 1 file changed, 6 insertions(+), 33 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/execution/ExecutionHelper.java b/platform/lang-impl/src/com/intellij/execution/ExecutionHelper.java index 2afdc436b3b7..fc257289ba80 100644 --- a/platform/lang-impl/src/com/intellij/execution/ExecutionHelper.java +++ b/platform/lang-impl/src/com/intellij/execution/ExecutionHelper.java @@ -270,54 +270,27 @@ public class ExecutionHelper { final int timeout) { return new Runnable() { private final Semaphore mySemaphore = new Semaphore(); - private final Object LOCK = new Object(); - private Boolean processedFinished = Boolean.FALSE; private final Runnable myProcessThread = new Runnable() { public void run() { try { - processHandler.waitFor(); - synchronized (LOCK) { - processedFinished = Boolean.TRUE; + final boolean finished = processHandler.waitFor(1000 * timeout); + if (!finished) { + LOG.error("Timeout (" + timeout + " sec) on executing: " + processHandler.getCommandLine()); + processHandler.destroyProcess(); } - } - finally { + } finally { mySemaphore.up(); } } }; - private final Runnable myTimeoutListener = new Runnable() { - public void run() { - try { - synchronized (this) { - try { - wait(1000 * timeout); - synchronized (LOCK) { - if (!processedFinished) { - LOG.error("Timeout (" + timeout + " sec) on executing: " + processHandler.getCommandLine()); - processHandler.destroyProcess(); - } - } - } - finally { - mySemaphore.up(); - } - } - } - catch (InterruptedException e) { - //Do nothing - } - } - }; - public void run() { mySemaphore.down(); ApplicationManager.getApplication().executeOnPooledThread(myProcessThread); - ApplicationManager.getApplication().executeOnPooledThread(myTimeoutListener); mySemaphore.waitFor(); } }; } -} \ No newline at end of file +}