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



+ 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() {
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;


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

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


+ 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
*/
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();
}
}
}


Loading…
Cancel
Save