URL connection timeouts… not timing out

Posted: April 14th, 2009 | Author: David | Filed under: Programming | Tags: | Comments Off

After much fussing about, I’ve found out that the default UrlConnection object in the core Java libraries doesn’t correctly obey connect or read timeouts set via the setConnectTimeout() or setReadTimeout() methods. The only way I’ve managed to get this to work, is to add the following arguments to the JVM.

-Dsun.net.client.defaultConnectTimeout=<CONNECT_TIMEOUT>
-Dsun.net.client.defaultReadTimeout=<READ_TIMEOUT>

In future, I’d be more inclined to use something like the Apache HttpCommons Client which provides a full-featured HTTP client.


Comments are closed.