Don't forget to set java.net.URL default timeouts!

Posted on Mon 25 August 2008

If your Java application uses java.net.URL, and chances it does are very high, and you are using Sun's JVM (since 1.4.2), you should set the sun.net.client.defaultConnectTimeout and sun.net.client.defaultReadTimeout system properties to a reasonable value. Otherwise, if a remote site hangs, your application or server will also hang.

This is what happened to Goojet this morning: because of a problem at our ISP, the TCP connections to some remote websites were just stuck, without succeeding nor failing. Our backend quickly became unresponsive, all threads waiting for remote connections.

We use HttpClient with timeouts in our own code, but the culprits were some third-party libraries that use java.net.URL for http access without allowing us to set timeouts.

Setting the default timeouts at the JVM level solved the issue, and our ISP solved its own issues a couple of hours later. Situation back to normal!



Lorem ipsum

Book review: Wicket in Action