Juan Manuel
Juan Manuel

Reputation: 178

HttpURLConnections ignore timeouts and never return

We are getting some unexpected results randomly from some servers when trying to open an InputStream from an HttpURLConnection. It seems like those servers would accept the connection and reply with a "stay-alive" header which will keep the Socket open but doesn't allow data to be sent back to the stream.

That scenario makes an attempt for a multi-threaded crawler a little "complicated", because if some connection gets stuck, the thread running it would never return... denying the completion of it's pool which derives in the controller thinking that some threads are still working.

Is there some way to read the connection response header to identify that "stay-alive" answer and avoid trying to open the stream??

Upvotes: 3

Views: 1770

Answers (2)

wds
wds

Reputation: 32283

I'm not sure what I'm missing here but it seems to me you simply need getHeaderField()?

Upvotes: 1

palindrom
palindrom

Reputation: 19101

Did you try setting "read time out", in addition to "connect time out"?

See http://java.sun.com/j2se/1.5.0/docs/api/java/net/URLConnection.html#setReadTimeout%28int%29

Upvotes: 1

Related Questions