How can a Java program find out if it is running in debug mode?
The application should behave a bit different in regular “full speed” mode than in “debug mode” (when a debugger is attached, when running in debug mode). The application communicates over TCP with either another computer, another process, or within itself. My co-worker wants us to use Socket.setSoTimeout(1000)
by default, so that reads from the socket can block for at most 1 second. When debugging, this is not enough of course, and the application stops working as it should. So a solution would be to set the SO_TIMEOUT
higher, but just in debug mode (for example: unlimited). Now, I don't always set breakpoints or don't want use a debug build where I could set the “debug” property myself. Sometimes I attach the debugger (remote debugging). I'm mainly using Eclipse so a solution that just works there is OK.
Possible answers include:
To find out if run in debug mode, use the following method in java.lang.management.*
or javax.management.*
...
Your co-worker is wrong for reason X, you shouldn't set SO_TIMEOUT
to 1 second by default.
I know about the system property approach, but I leave the question open to solve my original question.
Try opening a command prompt and enter "netstat -a" to see a list of ports that are currently in use on your machine. Then pick a port that's not in use.
In the Web. config file, locate the compilation element. Debugging is enabled when the debug attribute in the compilation element is set to true. Change the debug attribute to false to disable debugging for that application.
I found it out myself now:
boolean isDebug = java.lang.management.ManagementFactory.getRuntimeMXBean(). getInputArguments().toString().indexOf("jdwp") >= 0;
This will check if the Java Debug Wire Protocol agent is used.
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