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?