I am using the following JVM parameters to start-up a JVM with the hostpot debugger.
-Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=0
Note that I am assigning port zero, so that the JVM asks the OS for an ephemeral port. This is critical for my use-case, to make sure the JVM will not fail to start-up due to contention for some pre-defined port.
As a result my JVM starts-up, and the following log entry is outputted to stdout
:
Listening for transport dt_socket at address: XXXX
I would like to find some way to identify the debug port from inside or outside of the JVM, so it would be possible for me to record it in a state management serverice.
What options are available for this use-case? I have considered the following, with little joy:
From within VM:
Properties props = sun.misc.VMSupport.getAgentProperties();
System.out.println(props.getProperty("sun.jdwp.listenerAddress"));
From outside application:
VirtualMachine vm = com.sun.tools.attach.VirtualMachine.attach(PID);
try {
Properties props = vm.getAgentProperties();
System.out.println(props.getProperty("sun.jdwp.listenerAddress"));
} finally {
vm.detach();
}
Both are not a part of a standard. Applicable only to OpenJDK / Oracle JDK.
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