title: HttpURLConnection connection timeout not working
body: <p>I have set connection timeout and Read timeout but still they are getting ignored, the request just stays on forever. How do I set a timeout such that the request gets cancelled if the timeout is reached ? 
  This is my code snippet, appreciate your help.</p>
  
  <pre><code>        urlConnection = (HttpURLConnection) saveURL.openConnection();
          // is output buffer writer
          urlConnection.setRequestMethod("POST");
          urlConnection.setRequestProperty("Content-Type", "text/html");
          urlConnection.setRequestProperty("userid", id);
  
          urlConnection.setConnectTimeout(3000);
          urlConnection.setReadTimeout(3000);
          urlConnection.setDoInput(true);
          urlConnection.setDoOutput(true);
          urlConnection.setUseCaches(false);
  
          Writer writer = new BufferedWriter(new OutputStreamWriter(urlConnection.getOutputStream(), "UTF-8"));
          writer.write(jsonString);
          writer.flush();
          // json data
          writer.close();
  
          is = new BufferedInputStream(urlConnection.getInputStream());
          BufferedReader br = new BufferedReader(new InputStreamReader(is));
          String inputLine = "";
          while ((inputLine = br.readLine()) != null) {
              sb.append(inputLine);
          }
  
          int responseCode = urlConnection.getResponseCode();
  
      } catch (MalformedURLException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      } catch (ProtocolException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      } catch (UnsupportedEncodingException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      } catch (SocketTimeoutException soce) {
          // TODO Auto-generated catch block
          soce.printStackTrace();
      } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      } finally {
  
          try {
              if (null != urlConnection)
                  urlConnection.disconnect();
          } catch (Exception e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }
      }
  </code></pre>