I want my application to timeout in some specific seconds, but it keeps on trying to contact the specified URL until it gets a response. Below is the code I am using.
System.getProperties().setProperty("sun.net.client.defaultConnectTimeout", timeOut); System.getProperties().setProperty("sun.net.client.defaultReadTimeout", timeOut); URL url = new URL(targetURL); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); but if I set following property
connection.setConnectTimeout(Integer.parseInt(timeout)); then it gets timed out in desired time without waiting for server's response.
So, why doesn't it get timed out by using just the system properties?
Edit: Does it have anything to do with this behavior/bug? Or is there any relation with Java version, because the same code used to work in Java 1.4 but now I am using Java 1.7.