开发者

Pretending to be 'jconsole'

开发者_如何学JAVAI'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.


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) {}
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜