确保在 tomcat 被终止时终止由 Runtime.exec 启动的应用程序
我通过调用来启动几个外部进程,
Runtime.getRuntime.exec("java myApp");
我使用一些 java.concurent.Future 来监视应用程序的正确启动和执行。 我可以判断应用程序是否启动、错误或停止。我可以阻止它。
但是,当我终止主应用程序(启动其他应用程序的应用程序)时,子应用程序的几个进程继续运行,我失去了对它们的控制。
我正在寻找一种方法来确保当母应用程序被停止/杀死/错误时,所有子进程也被杀死。
我已经做了什么:
主应用程序在 tomcat 中运行,因此我监听上下文的破坏,并终止所有子进程。但这还不够:当 tomcat 停止或被杀死时,它就不起作用。
I launch several external process via a call to
Runtime.getRuntime.exec("java myApp");
I monitor the correct launching and execution of the application with some java.concurent.Future.
I can tell if the app is launched, in error, stopped. I can stop it.
But, when I kill the main application (the one who launches the others) the several processes of the children applications keep runnning and I lose control on them.
I looking for a way to ensure that when the mother application is stopped / killed / in error, all of the children process are killed as well.
What I have already done :
The main application runs in tomcat, so i listen for the destruction of the context, and kill all subprocesses. But it's not enough: when tomcat is stopped or killed, it's not working.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以做的是 - 让您的应用程序以一定的时间间隔打开到 tomcat(在 localhost:port 上)的连接,如果不存在 -
System.exit(0)
。例如:What you can do is - make your applications open a connection to the tomcat (on localhost:port) in certain intervals, and if it is not there -
System.exit(0)
. For example: