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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With