Java实现Linux下双守护进程(3)
复制代码 代码如下: public class GuardAMain { public static void main(String[] args) throws Exception { GuardA guardA = new GuardA(); Configure configure = new Configure(); GuardServer server =
复制代码 代码如下:
public class GuardAMain {
public static void main(String[] args) throws Exception {
GuardA guardA = new GuardA();
Configure configure = new Configure();
GuardServer server = new GuardServer(configure.getServername());
while (true) {
// 如果GuardB未运行 运行GuardB
if (!guardA.checkGuardB()) {
System.out.println("Start GuardB.....");
Runtime.getRuntime().exec(configure.getStartguardb());
}
// 检测服务器存活
if (server.checkServer() <= 0) {
boolean isServerDown = true;
// trip check
for (int i = 0; i < 3; i++) {
// 如果服务是存活着
if (server.checkServer() > 0) {
isServerDown = false;
break;
}
}
if (isServerDown)
server.startServer(configure.getStartserver());
}
Thread.sleep(configure.getInterval());
}
}
}
4、Shutdown实现
精彩图集
精彩文章