title: Can I set a timeout for the data transfer in a Java HttpURLConnection?
body: <p>I use </p>
  
  <pre><code>URLConnection urlConn = theURL.openConnection();
  
  // set connect timeout.
  urlConn.setConnectTimeout(5000);
  
  // set read timeout.
  urlConn.setReadTimeout(5000);
  </code></pre>
  
  <p>in my application. One timeout for the connection time, on for the time until the read starts. Is there any simple way to timeout the actual data transfer process?</p>
  
  <p>I have threads reading data from either very slow hosts, or the data source is very big, what leads to too long transfer times. How can I limit that time?</p>