Why would URLConnection timeout after 6+ minutes instead of 5 seconds?

Viewed 2663

I am copying this method verbatim from my application, which isn't complete yet but it does attempt to provide me with a timeout stack trace if things don't go smoothly:

protected boolean isHttpAlive()  {
  boolean isHttpOk = false;

  HttpURLConnection httpConnection = null;
  try {
    URL gurl = new URL("http://www.amazon.com/");
    URLConnection connection = gurl.openConnection();
    connection.setConnectTimeout(5 * 1000); // 5 seconds!
    httpConnection = (HttpURLConnection) connection;
    int responseCode = httpConnection.getResponseCode();
    if (responseCode == HttpURLConnection.HTTP_OK)
      isHttpOk = true;
  } 
  catch (Exception e) {                    
    e.printStackTrace();
  }
  finally {
    if (httpConnection != null)
      httpConnection.disconnect();
  }

  return isHttpOk;
}

Now on one of my test devices (Droid), when there is a problem, I do get the exception but only after 6 minutes and 36 seconds, not 5 seconds as I set in the code above.

The timeout exception is thrown for the getResponseCode().

Why?

What am I missing?

2 Answers
Related