title: Thread stuck in IN_NATIVE state while downloading a file from webservice
body: <p>I am downloading a file from X service thru my code. The downloaded file is written on file system. 
  Issue I am facing is that my instance is stuck and not taking further jobs to process. In the thread dump I see most of the threads in IN_NATIVE state. </p>
  
  <p>Can you please help me where I am going wrong?</p>
  
  <pre><code>    Thread 25493: (state = IN_NATIVE)
       - java.net.SocketInputStream.socketRead0(java.io.FileDescriptor, byte[], int, int, int) @bci=0 (Compiled frame; information may be imprecise)
       - java.net.SocketInputStream.read(byte[], int, int, int) @bci=87, line=152 (Compiled frame)
       - java.net.SocketInputStream.read(byte[], int, int) @bci=11, line=122 (Compiled frame)
       - sun.security.ssl.InputRecord.readFully(java.io.InputStream, byte[], int, int) @bci=21, line=442 (Compiled frame)
       - sun.security.ssl.InputRecord.read(java.io.InputStream, java.io.OutputStream) @bci=32, line=480 (Interpreted frame)
       - sun.security.ssl.SSLSocketImpl.readRecord(sun.security.ssl.InputRecord, boolean) @bci=44, line=927 (Interpreted frame)
       - sun.security.ssl.SSLSocketImpl.readDataRecord(sun.security.ssl.InputRecord) @bci=15, line=884 (Interpreted frame)
       - sun.security.ssl.AppInputStream.read(byte[], int, int) @bci=72, line=102 (Interpreted frame)
       - org.apache.http.impl.io.AbstractSessionInputBuffer.fillBuffer() @bci=71, line=160 (Compiled frame)
       - org.apache.http.impl.io.SocketInputBuffer.fillBuffer() @bci=1, line=84 (Compiled frame)
       - org.apache.http.impl.io.AbstractSessionInputBuffer.readLine(org.apache.http.util.CharArrayBuffer) @bci=130, line=273 (Compiled frame)
       - org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(org.apache.http.io.SessionInputBuffer) @bci=16, line=140 (Compiled frame)
       - org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(org.apache.http.io.SessionInputBuffer) @bci=2, line=57 (Compiled frame)
       - org.apache.http.impl.io.AbstractMessageParser.parse() @bci=38, line=260 (Compiled frame)
       - org.apache.http.impl.AbstractHttpClientConnection.receiveResponseHeader() @bci=8, line=283 (Compiled frame)
       - org.apache.http.impl.conn.DefaultClientConnection.receiveResponseHeader() @bci=1, line=251 (Compiled frame)
       - org.apache.http.impl.conn.ManagedClientConnectionImpl.receiveResponseHeader() @bci=6, line=197 (Compiled frame)
  
   - org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(org.apache.http.HttpRequest, org.apache.http.HttpClientConnection, org.apache.http.protocol.HttpContext) @bci=41, line=271 (Compiled frame)
  </code></pre>
  
  <p>Below is the code which is handling imputstream from X service</p>
  
  <pre><code>public void handleResponse(Response response, InputStream responseStream) throws IOException {
      FileOutputStream fos = null;
      BufferedOutputStream bos = null;
      BufferedInputStream bis = null;
      try {
          if (response != null &amp;&amp; responseStream != null) {
              bis = new java.io.BufferedInputStream(responseStream);
              //code writing to disk 
          }
      }
      catch (IOException e) {
          log.error("IOException while writing file " + fileName + " to disk ", e);
      }
      catch (Exception e) {
          log.error("IOException while writing file " + fileName + " to disk ", e);
      }
      finally {
          if (bos != null) {
              bos.close();
          }
          if (fos != null) {
              fos.close();
          }
          if (bis != null) {
              bis.close();
          }
      }
  }
  </code></pre>