@@ -53,6 +53,7 @@ public class ExecuteJava implements Runnable, TimeoutObserver { | |||||
private Long timeout = null; | private Long timeout = null; | ||||
private volatile Throwable caught = null; | private volatile Throwable caught = null; | ||||
private volatile boolean timedOut = false; | private volatile boolean timedOut = false; | ||||
private boolean done = false; | |||||
private Thread thread = null; | private Thread thread = null; | ||||
/** | /** | ||||
@@ -168,7 +169,9 @@ public class ExecuteJava implements Runnable, TimeoutObserver { | |||||
thread.start(); | thread.start(); | ||||
w.start(); | w.start(); | ||||
try { | try { | ||||
while (!done) { | |||||
wait(); | wait(); | ||||
} | |||||
} catch (InterruptedException e) { | } catch (InterruptedException e) { | ||||
// ignore | // ignore | ||||
} | } | ||||
@@ -228,6 +231,7 @@ public class ExecuteJava implements Runnable, TimeoutObserver { | |||||
perm.restoreSecurityManager(); | perm.restoreSecurityManager(); | ||||
} | } | ||||
synchronized (this) { | synchronized (this) { | ||||
done = true; | |||||
notifyAll(); | notifyAll(); | ||||
} | } | ||||
} | } | ||||
@@ -243,6 +247,7 @@ public class ExecuteJava implements Runnable, TimeoutObserver { | |||||
timedOut = true; | timedOut = true; | ||||
thread.interrupt(); | thread.interrupt(); | ||||
} | } | ||||
done = true; | |||||
notifyAll(); | notifyAll(); | ||||
} | } | ||||
@@ -312,7 +312,13 @@ public class Parallel extends Task | |||||
Thread timeoutThread = new Thread() { | Thread timeoutThread = new Thread() { | ||||
public synchronized void run() { | public synchronized void run() { | ||||
try { | 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) { | synchronized (semaphore) { | ||||
stillRunning = false; | stillRunning = false; | ||||
timedOut = true; | timedOut = true; | ||||
@@ -143,8 +143,14 @@ public class OutputStreamFunneler { | |||||
if (!funnel.closed) { | if (!funnel.closed) { | ||||
try { | try { | ||||
if (timeoutMillis > 0) { | if (timeoutMillis > 0) { | ||||
final long start = System.currentTimeMillis(); | |||||
final long end = start + timeoutMillis; | |||||
long now = System.currentTimeMillis(); | |||||
try { | try { | ||||
wait(timeoutMillis); | |||||
while (now < end) { | |||||
wait(end - now); | |||||
now = System.currentTimeMillis(); | |||||
} | |||||
} catch (InterruptedException eyeEx) { | } catch (InterruptedException eyeEx) { | ||||
//ignore | //ignore | ||||
} | } | ||||
@@ -117,9 +117,13 @@ public class WorkerAnt extends Thread { | |||||
* @throws InterruptedException if the execution was interrupted | * @throws InterruptedException if the execution was interrupted | ||||
*/ | */ | ||||
public void waitUntilFinished(long timeout) throws InterruptedException { | public void waitUntilFinished(long timeout) throws InterruptedException { | ||||
final long start = System.currentTimeMillis(); | |||||
final long end = start + timeout; | |||||
synchronized (notify) { | synchronized (notify) { | ||||
if (!finished) { | |||||
notify.wait(timeout); | |||||
long now = System.currentTimeMillis(); | |||||
while (!finished && now < end) { | |||||
notify.wait(end - now); | |||||
now = System.currentTimeMillis(); | |||||
} | } | ||||
} | } | ||||
} | } | ||||