是否可以通过JMX以编程方式关闭Java进程 [英] Is it possible to programmatically close a Java process through JMX
问题描述
我正在编写一个应用程序来监视另一个Java进程,并在遇到某些目标时采取特定的操作。例如,如果一个线程死锁一段时间,请终止线程,如果内存使用量超过特定数量,发送电子邮件警报并终止进程等等。
I'm currently writing an app to monitor another Java process and take specific actions when certain targets are hit. For example, if a thread deadlocks for a certain time, kill the thread, if the memory usage goes over a specific amount, send email alerts and kill the process, etc.
我的应用程序将作为一个独立的应用程序运行,监控特定的其他应用程序(本地,但从我可以看到远程或本地没有区别)。
My app will run as a stand-alone app, monitoring specific other apps (locally, though from what I can see remote or local makes no difference here).
我正在通过MXBeans监控外部JVM,但是看不到一种干净的方法来杀死外部进程,而不像kill -9这样的系统调用(I'顺便说一句,我在UNIX中工作。
I'm monitoring the external JVMs via MXBeans, but cannot see a clean way to kill the external process short of a system call like 'kill -9 ' (I'm working in UNIX by the way).
有没有办法通过MXBean接口杀死JVM?
Is there any way to kill a JVM through the MXBean interfaces?
Graham
推荐答案
当然。在目标服务器上实现一个调用 System.exit()
的MBean,并从客户端调用它作为JMX操作。
Sure. Implement an MBean on the target server that calls System.exit()
, and invoke that as a JMX operation from the client.
这篇关于是否可以通过JMX以编程方式关闭Java进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!