简体   繁体   中英

How to find dynamically allocated JMX port when port is 0

For a java application when jmx is enabled and the port is set 0, a port will be dynamically allocated:

-Dcom.sun.management.jmxremote.port=0

What is the best way to find out what port is allocated? I managed to find it out using ps and pfiles on Solaris, hoping there is a simpler why to find it (programmatically)

Also is there a better way to assign dynamic jmx ports to java applications on the same box and keep track of them?

This question was answered here

String url = sun.management.ConnectorAddressLink.importRemoteFrom(0)
        .get("sun.management.JMXConnectorServer.0.remoteAddress");
String portStr = url.substring(url.lastIndexOf(":") + 1, url.lastIndexOf("/jmxrmi"));      
int port = Integer.valueOf(portStr);
System.out.println(port);

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