Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
235 views
in Technique[技术] by (71.8m points)

java - 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 ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
    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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...