为什么在JVM退出时子进程死掉?我尝试了许多不同的方法,但都没有成功。我以为这个过程会独立完成。
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
try {
logger.info("Attempting to restart using\n" + cmd.toString());
ProcessBuilder pb = new ProcessBuilder("/opt/jdk1.8.0_121/bin/java" ,
"-Xms64m",
"-Xmx128m",
"-jar",
"/usr/share/pdfconverter-service/bin/pdfconverter-service.jar",
"--spring.config.location=/usr/share/pdfconverter-service/conf/application.properties");
pb.redirectOutput(logFile);
pb.redirectError(logFile);
pb.redirectErrorStream(true);
Process p = pb.start();
logger.info("Restart Initiated");
} catch (IOException e ) {
logger.error("Error restarting application", e);
logger.error(e.toString(), e);
}
}
});
// execute some custom code before restarting
if (runBeforeRestart != null) {
runBeforeRestart.run();
}
// exit
System.exit(0);