title: thread hangs in socketRead0 Java
body: <p>Basically I am trying to download a HTML content of a webpage. The method is very simple</p>
  
  <pre><code>        HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
          BufferReader in = new BufferedReader(new InputStreamReader(httpURLConnection.getInputStream()));
          String line;
          StringBuilder pageBuilder = new StringBuilder();
          while ((line = in.readLine()) != null) {
              pageBuilder.append(line + "\n");
          }
  </code></pre>
  
  <p>But sometimes the program just hangs. I tried to debug and the thread stack trace tells me that it hangs when calling to method SocketRead0. I tried to set readtimeout for the connection but it does not work. Any ideas on how can I detect and get through the block of SocketRead0 ?</p>
  
  <p>Edit: It seems that the problem I actually have is that getReponseCode implicitly calls some getInputStream and some read() methods and then hangs at readSocket0(). Is there anyway I can make sure that the call to getReponseCode() will be safe ?
  Here is the stack trace of one thread hanging: Level 0 is the most recent call</p>
  
  <pre><code>thread 24stacktrace
          At 0level
          at method socketRead0
          at line -2
          At 1level
          at method read
          at line 129
          At 2level
          at method fill
          at line 218
          At 3level
          at method read1
          at line 258
          At 4level
          at method read
          at line 317
          At 5level
          at method parseHTTPHeader
          at line 687
          At 6level
          at method parseHTTP
          at line 632
          At 7level
          at method getInputStream
          at line 1200
          At 8level
          at method getResponseCode
          at line 379
          At 9level
          at method pushFinalRedirectedURL
          at line 132
          At 10level
          at method process
          at line 134
          At 11level
          at method run
          at line 40
  </code></pre>