Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/330.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何用Java重新启动我的服务器_Java_Restart - Fatal编程技术网

如何用Java重新启动我的服务器

如何用Java重新启动我的服务器,java,restart,Java,Restart,这是关机的方法 public static void restart() { closeServices(); System.gc(); try { Runtime.getRuntime().exec("run.cmd"); System.exit(0); } catch (Throwable e) { Logger.handle(e); } } 这是run.cmd java -javaagent:"C:

这是关机的方法

public static void restart() {
    closeServices();
    System.gc();
    try {
        Runtime.getRuntime().exec("run.cmd");
        System.exit(0);
    } catch (Throwable e) {
        Logger.handle(e);
    }

}
这是run.cmd

java -javaagent:"C:\Program Files (x86)\ZeroTurnAround\JRebel\jrebel.jar" -cp bin;data/FileStore.jar;data/netty-3.5.2.Final.jar;xstream-1.4.3.jar;data/mysql.jar com.rs.Launcher

如何使其显示运行run.cmd并关闭最后一个命令?现在它只需退出当前服务器,而不启动新服务器。

使用

taskkill /F /IM java.exe
这当然可以

以编程方式:-

public static void restart() {
    closeServices();
    System.gc();
    try {
        Runtime.getRuntime().exec("taskkill /F /IM java.exe");
        System.exit(0);
    } catch (Throwable e) {
        Logger.handle(e);
    }    
} 

我不确定,但很可能,杀死VM也会杀死所有子进程在开始创建新实例之前,确保上一个实例已关闭?使用@jochen和+1时,您的本机exec处理可能不知道如何使用cmd执行.cmd文件。