title: How to find out if "debug mode" is enabled
body: <p>How can a Java program find out if it is running in debug mode? </p>
  
  <p>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 <code>Socket.setSoTimeout(1000)</code> 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 <code>SO_TIMEOUT</code> 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.</p>
  
  <p>Possible answers include: </p>
  
  <ol>
  <li><p>To find out if run in debug mode, use the following method in <code>java.lang.management.*</code> or <code>javax.management.*</code> ...</p></li>
  <li><p>Your co-worker is wrong for reason X, you shouldn't set <code>SO_TIMEOUT</code> to 1 second by default.</p></li>
  </ol>
  
  <h2>Update</h2>
  
  <p>I know about the system property approach, but I leave the question open to solve my original question.</p>