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.
Update
I know about the system property approach, but I leave the question open to solve my original question.
question from:
https://stackoverflow.com/questions/3776204/how-to-find-out-if-debug-mode-is-enabled 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…