I have 16 Java processes with the same main method and arguments running on one machine. I wish to monitor these remotely thru JConsole.
Hard coding port numbers like -Dcom.sun.management.jmxremote.port=5000
won't work because these processes are using same configuration and they can't work with same port.
Is it possible for the JVM to select a different port dynamically for each of the 16 processes?
Using RMI Connector might be the way as you may specify URL of your agent.
In case you'd need it, you may create RMI registry programatically using:
java.rmi.registry.LocateRegistry.createRegistry(port);
You may find following unrelated sample useful: Connecting Through Firewall Using JMX
I don't think the oracle jvm supports anything like this. the only thing that might work is using the port "0", which enables "dynamic" port selection in some rmi related stuff.
来源:https://stackoverflow.com/questions/7112052/jmx-port-dynamic-allocation