在使用具有临时端口的JMX服务器时,如何获取服务器端口号? [英] When using a JMX server with ephemeral port, how to get the server port number?

查看:105
本文介绍了在使用具有临时端口的JMX服务器时,如何获取服务器端口号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用以下选项启动Java应用程序时:

When launching a Java application with these options:

-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.port=0
-Dcom.sun.management.jmxremote.local.only=false

Java使用临时端口,这对于避免冲突非常有用.

Java uses an ephemeral port, which is very useful to avoid collisions.

是否可以从应用程序内部以编程方式获取实际端口(或连接URL)?

Is it possible to get the actual port (or connection URL) programmatically from within the application ?

推荐答案

    String url = sun.management.ConnectorAddressLink.importRemoteFrom(0)
            .get("sun.management.JMXConnectorServer.0.remoteAddress");
    System.out.println(url);

这将打印类似的URL

This will print URL like

service:jmx:rmi:///jndi/rmi://hostname:57025/jmxrmi

这篇关于在使用具有临时端口的JMX服务器时,如何获取服务器端口号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆