title: HttpURLConnection timeout not working by setting the system properties
body: <p>I want my application to timeout in some specific seconds, but it keeps on trying to contact the specified URL until it gets a response. Below is the code I am using.</p>
  
  <pre><code>System.getProperties().setProperty("sun.net.client.defaultConnectTimeout", timeOut);
  
  System.getProperties().setProperty("sun.net.client.defaultReadTimeout", timeOut); 
  
  URL url = new URL(targetURL);
  
  HttpURLConnection connection = (HttpURLConnection) url.openConnection();
  </code></pre>
  
  <p>but if I set following property</p>
  
  <pre><code>connection.setConnectTimeout(Integer.parseInt(timeout));
  </code></pre>
  
  <p>then it gets timed out in desired time without waiting for server's response.</p>
  
  <p>So, why doesn't it get timed out by using just the system properties?</p>
  
  <p><strong>Edit</strong>: Does it have anything to do with this <a href="http://bugs.java.com/bugdatabase/view_bug.do?bug_id=6245589" rel="nofollow">behavior/bug</a>? Or is there any relation with Java version, because the same code used to work in Java 1.4 but now I am using Java 1.7.</p>