views:

478

answers:

2

I was having a problem where HttpURLConnection.getOutputStream() took 2-3 seconds. I set the connect timeout using HttpURLConnection.setConnectTimeout, expecting a SocketTimeoutException (wrapped by IOException) to be thrown from getOutputStream(), so I could retry the whole operation on another server.

Instead, it just works now. Does getOutputStream() try to connect internally if it gets a SocketTimeoutException?

A: 

Isn't this addressed here?

No, I don't think so.
ripper234
"Some non-standard implmentation of this method may ignore the specified timeout. To see the connect timeout set, please call getConnectTimeout()."
+1  A: 

If you setConnectTimeout(), it will not retry. Otherwise, it tries just one more time before it throws IOException.

In my opinion, you should handle retry yourself though.

ZZ Coder
Do you have a reference for this?
ripper234
No. We found out this behavior while looking at some HTTP traces and confirmed by looking at Java 5 source code. So this is only a special behavior of Java 5's URL handler.
ZZ Coder
The thing is ... I found that setting the timeout did seem to cause internal retries. I'm downloading the code now.
ripper234