假装是“jconsole”

发布于 2024-10-08 14:52:08 字数 130 浏览 0 评论 0原文

我想避免为进程分配特定的 TCP 端口,但仍然能够与其中的 JMX MBean 建立(本地)连接。我不断看到证据表明这应该是可能的,但我无法弄清楚我将使用什么作为 JNDI 名称来引用某些此类进程,或者像 jconsole 那样迭代所有这些进程。

I'd like to avoid assigning specific TCP ports to processes, but still be able to make (local) connection to the JMX MBeans inside them. I keep seeing evidence that this should be possible, but I cannot work out what I'd use as a JNDI name to reference some such process, or to iterate over all of them as jconsole does.

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

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

发布评论

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

评论(1

英雄似剑 2024-10-15 14:52:08

我相信您正在寻找 Attach API< /a> 不会(表面上)使用 JNDI 名称,而只是通过 PID 连接。这不是一个坏方法,但我不确定是否所有 JVM 都实现了这个 API。这是 groovy 中的一个快速示例:

import com.sun.tools.attach.*;

VirtualMachine.list().each() { vmd ->
    try {
        VirtualMachine vm = VirtualMachine.attach(vmd);
        println vm;
    } catch (Exception e) {}
}

I believe you're looking for the Attach API which will not (outwardly) use a JNDI name and simply connects by PID. It's not a bad way to go, but I am not sure if all JVMs implement this API. Here's a quickie example in groovy:

import com.sun.tools.attach.*;

VirtualMachine.list().each() { vmd ->
    try {
        VirtualMachine vm = VirtualMachine.attach(vmd);
        println vm;
    } catch (Exception e) {}
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文