简体   繁体   中英

When using a JMX server with ephemeral port, how to get the server port number?

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 uses an ephemeral port, which is very useful to avoid collisions.

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

This will print URL like

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM