【发布时间】:2012-03-04 21:14:39
【问题描述】:
我有一个案例,我需要执行System.exit(0);,然后在内核恐慌或类似情况下立即重新启动同一个应用程序。但是,如果我首先调用 System.exit(0) 我如何调用 exec() ?就像在 linux 中一样,我让它与 BASH 一起工作。
#!/bin/bash
pkill java;
sleep 1;
java -cp /var/tmp/dist/Kernel.jar main.Kernel
Main.java:
/* Windows platform running */
public class Main {
public static void main(String[] args)
{
// other activity happening.... for ages
//
// Suddently there will be a kernel panic it is better to do a software reboot
// remotely
//
}
public static rebootSoftwareKernel()
{
System.exit(0); // Exit completely
Runtime.getRuntime().exec( MyConstant.RunItSelfSoftReboot() ); // Restart this same
}
}
【问题讨论】:
-
可以在调用exit之前运行reboot吗?有没有可能在关闭旧进程之前启动新进程?另外, pkill 是最好的选择吗?如果有其他 Java 进程在运行怎么办?
-
当我打电话给
exec(); System.exit(0);它不同步。因为 exec 执行的是同一个活动实例,所以不能重复。所以它失败了。
标签: java windows executable-jar