379116: start.jar fix to shutdown child processes with --exec. Remove finally block and replace with a shutdown hook in _exec if branch.

Change-Id: I85af53090a2797f433aca22276b413762999a477
This commit is contained in:
Thomas Becker 2012-05-10 17:04:47 +02:00
parent 5687aa8beb
commit d7fec35028
1 changed files with 16 additions and 13 deletions

View File

@ -550,22 +550,25 @@ public class Main
if (_exec)
{
CommandLineBuilder cmd = buildCommandLine(classpath,configuredXmls);
ProcessBuilder pbuilder = new ProcessBuilder(cmd.getArgs());
final Process process = pbuilder.start();
Runtime.getRuntime().addShutdownHook(new Thread()
{
@Override
public void run()
{
Config.debug("Destroying " + process);
process.destroy();
}
});
copyInThread(process.getErrorStream(),System.err);
copyInThread(process.getInputStream(),System.out);
copyInThread(System.in,process.getOutputStream());
monitor.setProcess(process);
process.waitFor();
try
{
copyInThread(process.getErrorStream(),System.err);
copyInThread(process.getInputStream(),System.out);
copyInThread(System.in,process.getOutputStream());
monitor.setProcess(process);
process.waitFor();
}
finally
{
Config.debug("Destroying " + process);
process.destroy();
}
return;
}