Ant shutdown PR: 8510 git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274821 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -450,27 +450,30 @@ public class Execute { | |||||
| } | } | ||||
| streamHandler.start(); | 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) { | protected void waitFor(Process process) { | ||||
| @@ -153,7 +153,7 @@ public class ExecuteWatchdog implements TimeoutObserver { | |||||
| // We must check if the process was not stopped | // We must check if the process was not stopped | ||||
| // before being here | // before being here | ||||
| process.exitValue(); | process.exitValue(); | ||||
| } catch (IllegalThreadStateException itse){ | |||||
| } catch (IllegalThreadStateException itse) { | |||||
| // the process is not terminated, if this is really | // the process is not terminated, if this is really | ||||
| // a timeout and not a manual stop then kill it. | // a timeout and not a manual stop then kill it. | ||||
| if (watch){ | if (watch){ | ||||
| @@ -214,6 +214,7 @@ class ProcessDestroyer implements Runnable { | |||||
| synchronized (processes) { | synchronized (processes) { | ||||
| boolean processRemoved = processes.removeElement(process); | boolean processRemoved = processes.removeElement(process); | ||||
| if (processes.size() == 0) { | if (processes.size() == 0) { | ||||
| processes.notify(); | |||||
| removeShutdownHook(); | removeShutdownHook(); | ||||
| } | } | ||||
| return processRemoved; | return processRemoved; | ||||
| @@ -229,6 +230,13 @@ class ProcessDestroyer implements Runnable { | |||||
| while (e.hasMoreElements()) { | while (e.hasMoreElements()) { | ||||
| ((Process) e.nextElement()).destroy(); | ((Process) e.nextElement()).destroy(); | ||||
| } | } | ||||
| try { | |||||
| // wait for all processes to finish | |||||
| processes.wait(); | |||||
| } catch (InterruptedException interrupt) { | |||||
| // ignore | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| @@ -114,7 +114,8 @@ public class Watchdog implements Runnable { | |||||
| while (!stopped && until > (now = System.currentTimeMillis())) { | while (!stopped && until > (now = System.currentTimeMillis())) { | ||||
| try { | try { | ||||
| wait(until - now); | wait(until - now); | ||||
| } catch (InterruptedException e) {} | |||||
| } catch (InterruptedException e) { | |||||
| } | |||||
| } | } | ||||
| if (!stopped) { | if (!stopped) { | ||||
| fireTimeoutOccured(); | fireTimeoutOccured(); | ||||