【问题标题】:Java - How do i close myself and restart myself, such as my software kernel panic and i need reboot itself?Java - 我如何关闭自己并重新启动自己,例如我的软件内核恐慌并且我需要重新启动自己?
【发布时间】: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


【解决方案1】:

查看Tanuki Service Wrapper。除其他功能外,它还允许在需要时重新启动 JVM。

【讨论】:

    猜你喜欢
    • 2011-07-05
    • 1970-01-01
    • 2013-02-18
    • 1970-01-01
    • 1970-01-01
    • 2022-09-25
    • 1970-01-01
    • 1970-01-01
    • 2021-08-27
    相关资源
    最近更新 更多