Need timeout setting for remote data request made using java.net.URL class. After some googling found out that there are two system properties which can be used to set timeout for URL class as follows.
sun.net.client.defaultConnectTimeout
sun.net.client.defaultReadTimeout
I don't have control over all the systems and don't want everybody to keep setting the system properties. Is there any other alternative for making remote request which will allow me to set timeouts. Without any library, If available in java itself is preferable.
If you're opening a
URLConnection
fromURL
you can set the timeouts this way:How are you using the
URL
or what are you passing it to?A common replacement is the Apache Commons HttpClient, it gives much more control over the entire process of fetching HTTP URLs.