是否可以通过 JMX 以编程方式关闭 Java 进程

发布于 2024-08-08 17:48:11 字数 305 浏览 3 评论 0原文

我目前正在编写一个应用程序来监视另一个 Java 进程,并在达到某些目标时采取特定操作。例如,如果线程死锁一段时间,则终止该线程,如果内存使用量超过特定数量,则发送电子邮件警报并终止进程等。

我的应用程序将作为独立应用程序运行,监视特定的其他应用程序应用程序(本地,但据我所知,远程或本地没有区别)。

我正在通过 MXBeans 监视外部 JVM,但没有找到一种干净的方法来终止外部进程,除非使用像“kill -9”这样的系统调用(顺便说一句,我正在 UNIX 中工作)。

有没有办法通过 MXBean 接口杀死 JVM?

格雷厄姆

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).

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).

Is there any way to kill a JVM through the MXBean interfaces?

Graham

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

青衫负雪 2024-08-15 17:48:11

当然。在目标服务器上实现一个调用 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.

爱的故事 2024-08-15 17:48:11

如果您使用 Spring,您可以简单地注释您的 bean,使其操作之一公开为 MBean 操作.所以它会是这样的:

@MBeanOperation(description="Kill the service")
public void die() {
  System.exit();
}

...或者也许自己停止应用程序上下文。

If you're using Spring, you can simply annotate your bean to have one of its operations being exposed as an MBean operation. So it would be something like this:

@MBeanOperation(description="Kill the service")
public void die() {
  System.exit();
}

... or perhaps stop the application context yourself.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文