我需要从 Java 代码重新启动 tomcat。
例如,如果某个查询在一段时间内没有执行,那么它将自动重新启动 tomcat。
我已经尝试了以下关闭和启动代码,但是当我们关闭tomcat时,java代码将不会运行并且tomcat不会启动。
注意:- 我正在从应用程序运行此代码,并重新启动同一应用程序正在使用的同一个 tomact。
遵循代码
try {
PreparedStatement.setQueryTimeout(10);
rs = PreparedStatement.executeQuery();
} catch (SQLException ex) {
System.out.println("IN CATCH BLOCK FOR THE REFRESH INVOICE");
String shutcommand = "killall java";
Process shutchild = Runtime.getRuntime().exec(shutcommand);
System.out.println("JAVA PROCESS KILLED");
String locationCommand = "cd /root/cluster/tomcat6/bin";
Process locationChild = Runtime.getRuntime().exec(locationCommand);
String strtcommand = "./startup.sh";
Process strtchild = Runtime.getRuntime().exec(strtcommand);
}
在 SQLException 之后杀死 tomcat 这不是处理此异常的好主意。问题可能出在数据库站点上。
但是,如果您确定这就是您所需要的,您可以在本节中终止此 java 进程,但要运行 tomcat,您应该使用 bash 和 cron 等。为什么?因为杀死你的执行代码后就会停止,所以你无法实现启动tomcat的行。
如何检查tomcat:Tomcat 正在运行吗? https://stackoverflow.com/questions/3944157/is-tomcat-running
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)