基于我在 Stackoverflow 和互联网上其他页面上看到的代码,我创建了一种方法来停止和启动 tomcat,此时我将在系统中运行一个进程,因为我需要清理操作系统中的内存,我使用System.gc()
但仍然不足以释放内存,这是代码:
全球声明:
private String server = "localhost";
停止启动tomcat的方法:
public void tomcat(){
try{
Socket s = new Socket(server,8005);
if(s.isConnected()){
PrintWriter print = new PrintWriter(s.getOutputStream(),true);
print.println("SHUTDOWN"); /*Command to stop tomcat according to the line "<Server port="8005" shutdown="SHUTDOWN">" in catalina_home/conf/server.xml*/
print.close();
s.close();
}
Runtime.getRuntime().exec(System.getProperty("catalina.home")+"\\bin\\startup.bat"); /*Instruction to run tomcat after it gets stopped*/
}catch (Exception ex){
ex.printStackTrace();
}
}
启动 tomcat 的代码行工作正常,但没有停止它的指令,因为当我实例化套接字时,会给出以下消息:Connection refused: connect
.
我该如何解决这个问题?或者,还有其他方法可以阻止tomcat吗?
提前致谢。
public static void shut_server(String lien)
{
try {
Process child = Runtime.getRuntime().exec(lien+"/shutdown.sh");
System.out.println("Serveur est atteins");
} catch (IOException ex) {
Logger.getLogger(Installation.class.getName()).log(Level.SEVERE, null, ex);
System.out.println("erreur de demarrage");
}
}
lien = tomcat bin 文件的路径
例如 -/home/zakaria/Téléchargements/apache-tomcat-8.0.21/bin
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)