I am copying this method verbatim from my application, which is not yet complete, but it is trying to provide me with a trace of the timeout stack if everything goes not so 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 get an exception , but only after 6 minutes and 36 seconds , and not 5 seconds, as I installed in the above code.
A timeout exception has been getResponseCode() for getResponseCode() .
Why?
What am I missing?
Regex roookie
source share