写了一个监护程序,每隔30秒检查一次进程列表,假如没有找到tomcatw.exe进程就自动重启tomcat,实在是下策阿!希望我的程序对大家能够有用!
private void keepTomcatAlive() throws NullPointerException { String s; int i = 0; String t = new String(“tomcatw.exe”); boolean isTomcatAlive = false; try { java.lang.Process p = java.lang.Runtime.getRuntime().exec(“tasklist”); java.io.BufferedReader in = new java.io.BufferedReader(new java.io.InputStreamReader(p.getInputStream())); while((s = in.readLine()) != null) { if(s.startsWith(t)) isTomcatAlive = true; //System.out.println(s); }} catch (Exception e) {e.printStackTrace();} System.out.println(“Is Tomcat alive? Answer: ” + isTomcatAlive); if(isTomcatAlive == false) restartTomcat(); } public void restartTomcat() { try{ java.lang.Process p = java.lang.Runtime.getRuntime().exec(“/”C://Tomcat 5.0//bin//tomcatw.exe/” //GT//Tomcat5”); } catch (Exception e) {e.printStackTrace();} }