ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject [02/12] ant git commit: deal with spurious wakeups
Date Wed, 21 Dec 2016 15:59:51 GMT
deal with spurious wakeups


Project: http://git-wip-us.apache.org/repos/asf/ant/repo
Commit: http://git-wip-us.apache.org/repos/asf/ant/commit/f79b8e93
Tree: http://git-wip-us.apache.org/repos/asf/ant/tree/f79b8e93
Diff: http://git-wip-us.apache.org/repos/asf/ant/diff/f79b8e93

Branch: refs/heads/master
Commit: f79b8e9354f3108954ad9b50568ccb3cba6a8587
Parents: 9d53fea
Author: Stefan Bodewig <bodewig@apache.org>
Authored: Wed Dec 21 14:41:17 2016 +0100
Committer: Stefan Bodewig <bodewig@apache.org>
Committed: Wed Dec 21 15:18:05 2016 +0100

----------------------------------------------------------------------
 src/main/org/apache/tools/ant/taskdefs/ExecuteJava.java      | 5 +++++
 src/main/org/apache/tools/ant/taskdefs/Parallel.java         | 8 +++++++-
 src/main/org/apache/tools/ant/util/OutputStreamFunneler.java | 8 +++++++-
 src/main/org/apache/tools/ant/util/WorkerAnt.java            | 8 ++++++--
 4 files changed, 25 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ant/blob/f79b8e93/src/main/org/apache/tools/ant/taskdefs/ExecuteJava.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/taskdefs/ExecuteJava.java b/src/main/org/apache/tools/ant/taskdefs/ExecuteJava.java
index b78b9a6..ce6276b 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();
     }
 

http://git-wip-us.apache.org/repos/asf/ant/blob/f79b8e93/src/main/org/apache/tools/ant/taskdefs/Parallel.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/taskdefs/Parallel.java b/src/main/org/apache/tools/ant/taskdefs/Parallel.java
index 0f8512a..469ba41 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;

http://git-wip-us.apache.org/repos/asf/ant/blob/f79b8e93/src/main/org/apache/tools/ant/util/OutputStreamFunneler.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/util/OutputStreamFunneler.java b/src/main/org/apache/tools/ant/util/OutputStreamFunneler.java
index 6694c3f..9b4cef3 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
                     }

http://git-wip-us.apache.org/repos/asf/ant/blob/f79b8e93/src/main/org/apache/tools/ant/util/WorkerAnt.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/util/WorkerAnt.java b/src/main/org/apache/tools/ant/util/WorkerAnt.java
index 288d74d..768f387 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();
             }
         }
     }


Mime
View raw message