Is there a way to set a timeout for a URLConnection?

Tim Rohaly

There is no way to get a reference to the underlying socket used by the URLConnection, so there is no way to set the timeout value for that socket. If you really need this capability, you can create your own protocol handler for the protocol you are using in your URL (e.g. HTTP) - your protocol handler is then responsible for implementing all the protocol specifics, including creating the socket and setting a timeout value.

See also http://www.jguru.com/jguru/faq/view.jsp?EID=26381 and http://www.jguru.com/jguru/faq/view.jsp?EID=47460.