简体   繁体   中英

how to allocate dynamic port and get details of that[JMX]

Requirement: I want to run multiple process(with remote properties ieDcom.sun.management.jmxremote.port ) that can be view remotely via JMX on another machine.

Initially Dcom.sun.management.jmxremote.port= 9875 (picking from properties files) but it stricts me to run single process only.saving port information from the machine(where i am running process) in database for further use .

Then I used -Dcom.sun.management.jmxremote.port= 0 for dynamic port allocation to run multiple process.Now i can run multiple process but i am not able to get the port information so that i can save that information in database that will be used further for remote connection.

Thanks.

I have used this trick to get dynamic port

ServerSocket socket = new ServerSocket(0); int jmxPort = socket.getLocalPort();

This will allocate a dynamic port and then pass it to as VM args Dcom.sun.management.jmxremote.port=jmxPort

jmx port can be saved in database and can be used when need to make JMX connection.

Hope will be helpful.

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