Reputation: 800
For example, we can enable java remote debug by adding following to command line.
-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005
But my application is running in yarn, I'm not sure which port is available.
So I want enable java debug in my code.
First I detect a available port and log in my program, then I can use this port to debug my application.
Upvotes: 2
Views: 8041
Reputation: 893
I'm not sure this can be done from code; however according to an answer to this old question, it is possible to enable debugging for an already-running JVM using jsadebugd
As mentioned in said answer, the feature is marked experimental and unsupported so your mileage may vary.
Upvotes: 1
Reputation: 274
The address property specifies host (optionally) and port (only the port if host is left out). So address=5005
specifies the port 5005 in your case. If you want your program to wait until you connect your debugger, switch suspend=n
to suspend=y
.
Edit: Maybe I misunderstood your question. In case you want to enable debugging programmatically, this won't be possible as the debugging facility JPDA is not exposing a Java API nor any other way to start and stop it programmatically.
Upvotes: 1