Browse Source

deal with spurious wakeups

master
Stefan Bodewig 8 years ago
parent
commit
f79b8e9354
4 changed files with 25 additions and 4 deletions
  1. +5
    -0
      src/main/org/apache/tools/ant/taskdefs/ExecuteJava.java
  2. +7
    -1
      src/main/org/apache/tools/ant/taskdefs/Parallel.java
  3. +7
    -1
      src/main/org/apache/tools/ant/util/OutputStreamFunneler.java
  4. +6
    -2
      src/main/org/apache/tools/ant/util/WorkerAnt.java

+ 5
- 0
src/main/org/apache/tools/ant/taskdefs/ExecuteJava.java View File

@@ -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();
} }




+ 7
- 1
src/main/org/apache/tools/ant/taskdefs/Parallel.java View File

@@ -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;


+ 7
- 1
src/main/org/apache/tools/ant/util/OutputStreamFunneler.java View File

@@ -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
} }


+ 6
- 2
src/main/org/apache/tools/ant/util/WorkerAnt.java View File

@@ -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();
} }
} }
} }


Loading…
Cancel
Save