diff --git a/src/main/org/apache/tools/ant/taskdefs/ExecuteJava.java b/src/main/org/apache/tools/ant/taskdefs/ExecuteJava.java index b78b9a6a5..ce6276bb1 100644 --- a/src/main/org/apache/tools/ant/taskdefs/ExecuteJava.java +++ b/src/main/org/apache/tools/ant/taskdefs/ExecuteJava.java @@ -53,6 +53,7 @@ public class ExecuteJava implements Runnable, TimeoutObserver { private Long timeout = null; private volatile Throwable caught = null; private volatile boolean timedOut = false; + private boolean done = false; private Thread thread = null; /** @@ -168,7 +169,9 @@ public class ExecuteJava implements Runnable, TimeoutObserver { thread.start(); w.start(); try { + while (!done) { wait(); + } } catch (InterruptedException e) { // ignore } @@ -228,6 +231,7 @@ public class ExecuteJava implements Runnable, TimeoutObserver { perm.restoreSecurityManager(); } synchronized (this) { + done = true; notifyAll(); } } @@ -243,6 +247,7 @@ public class ExecuteJava implements Runnable, TimeoutObserver { timedOut = true; thread.interrupt(); } + done = true; notifyAll(); } diff --git a/src/main/org/apache/tools/ant/taskdefs/Parallel.java b/src/main/org/apache/tools/ant/taskdefs/Parallel.java index 0f8512af8..469ba418e 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Parallel.java +++ b/src/main/org/apache/tools/ant/taskdefs/Parallel.java @@ -312,7 +312,13 @@ public class Parallel extends Task Thread timeoutThread = new Thread() { public synchronized void run() { try { - wait(timeout); + final long start = System.currentTimeMillis(); + final long end = start + timeout; + long now = System.currentTimeMillis(); + while (now < end) { + wait(end - now); + now = System.currentTimeMillis(); + } synchronized (semaphore) { stillRunning = false; timedOut = true; diff --git a/src/main/org/apache/tools/ant/util/OutputStreamFunneler.java b/src/main/org/apache/tools/ant/util/OutputStreamFunneler.java index 6694c3f07..9b4cef3c6 100644 --- a/src/main/org/apache/tools/ant/util/OutputStreamFunneler.java +++ b/src/main/org/apache/tools/ant/util/OutputStreamFunneler.java @@ -143,8 +143,14 @@ public class OutputStreamFunneler { if (!funnel.closed) { try { if (timeoutMillis > 0) { + final long start = System.currentTimeMillis(); + final long end = start + timeoutMillis; + long now = System.currentTimeMillis(); try { - wait(timeoutMillis); + while (now < end) { + wait(end - now); + now = System.currentTimeMillis(); + } } catch (InterruptedException eyeEx) { //ignore } diff --git a/src/main/org/apache/tools/ant/util/WorkerAnt.java b/src/main/org/apache/tools/ant/util/WorkerAnt.java index 288d74dd5..768f38744 100644 --- a/src/main/org/apache/tools/ant/util/WorkerAnt.java +++ b/src/main/org/apache/tools/ant/util/WorkerAnt.java @@ -117,9 +117,13 @@ public class WorkerAnt extends Thread { * @throws InterruptedException if the execution was interrupted */ public void waitUntilFinished(long timeout) throws InterruptedException { + final long start = System.currentTimeMillis(); + final long end = start + timeout; synchronized (notify) { - if (!finished) { - notify.wait(timeout); + long now = System.currentTimeMillis(); + while (!finished && now < end) { + notify.wait(end - now); + now = System.currentTimeMillis(); } } }