Browse Source

Ensure terminated processes are allowed to complete before finishing the

Ant shutdown

PR:	8510


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274821 13f79535-47bb-0310-9956-ffa450edef68
master
Conor MacNeill 22 years ago
parent
commit
743a75153a
4 changed files with 31 additions and 19 deletions
  1. +20
    -17
      src/main/org/apache/tools/ant/taskdefs/Execute.java
  2. +1
    -1
      src/main/org/apache/tools/ant/taskdefs/ExecuteWatchdog.java
  3. +8
    -0
      src/main/org/apache/tools/ant/taskdefs/ProcessDestroyer.java
  4. +2
    -1
      src/main/org/apache/tools/ant/util/Watchdog.java

+ 20
- 17
src/main/org/apache/tools/ant/taskdefs/Execute.java View File

@@ -450,27 +450,30 @@ public class Execute {
}
streamHandler.start();

// add the process to the list of those to destroy if the VM exits
//
processDestroyer.add(process);
try {
// add the process to the list of those to destroy if the VM exits
//
processDestroyer.add(process);

if (watchdog != null) {
watchdog.start(process);
}
waitFor(process);
if (watchdog != null) {
watchdog.start(process);
}
waitFor(process);

// remove the process to the list of those to destroy if the VM exits
//
processDestroyer.remove(process);
if (watchdog != null) {
watchdog.stop();
}
streamHandler.stop();

if (watchdog != null) {
watchdog.stop();
}
streamHandler.stop();
if (watchdog != null) {
watchdog.checkException();
if (watchdog != null) {
watchdog.checkException();
}
return getExitValue();
} finally {
// remove the process to the list of those to destroy if the VM exits
//
processDestroyer.remove(process);
}
return getExitValue();
}

protected void waitFor(Process process) {


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

@@ -153,7 +153,7 @@ public class ExecuteWatchdog implements TimeoutObserver {
// We must check if the process was not stopped
// before being here
process.exitValue();
} catch (IllegalThreadStateException itse){
} catch (IllegalThreadStateException itse) {
// the process is not terminated, if this is really
// a timeout and not a manual stop then kill it.
if (watch){


+ 8
- 0
src/main/org/apache/tools/ant/taskdefs/ProcessDestroyer.java View File

@@ -214,6 +214,7 @@ class ProcessDestroyer implements Runnable {
synchronized (processes) {
boolean processRemoved = processes.removeElement(process);
if (processes.size() == 0) {
processes.notify();
removeShutdownHook();
}
return processRemoved;
@@ -229,6 +230,13 @@ class ProcessDestroyer implements Runnable {
while (e.hasMoreElements()) {
((Process) e.nextElement()).destroy();
}

try {
// wait for all processes to finish
processes.wait();
} catch (InterruptedException interrupt) {
// ignore
}
}
}
}

+ 2
- 1
src/main/org/apache/tools/ant/util/Watchdog.java View File

@@ -114,7 +114,8 @@ public class Watchdog implements Runnable {
while (!stopped && until > (now = System.currentTimeMillis())) {
try {
wait(until - now);
} catch (InterruptedException e) {}
} catch (InterruptedException e) {
}
}
if (!stopped) {
fireTimeoutOccured();


Loading…
Cancel
Save