Skip to main content
added 120 characters in body
Source Link
Aakash
  • 1k
  • 3
  • 16
  • 29

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.

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?

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.

edited tags
Link
Aakash
  • 1k
  • 3
  • 16
  • 29
added 132 characters in body
Source Link
Aakash
  • 1k
  • 3
  • 16
  • 29

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?

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?

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?

added 73 characters in body
Source Link
Aakash
  • 1k
  • 3
  • 16
  • 29
Loading
Source Link
Aakash
  • 1k
  • 3
  • 16
  • 29
Loading