• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

URL connection connectiontimeout and readtimeout issues

 
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

I need to know the feature of connectiontimeout setting for URLConnection. Can anyone provide concrete answer for my below questions:

1. When can we set connectiontimeout?
2. If I give some value in milliseconds for connectiontimeout, what will happen while connecting specific URL?
3. If I am unable to read my Inputstream after connection established, can connectiontimeout property take care of that particular connectivity?,else should we set property for readtimeout also?

example code:



Thanks,
selva
 
Sheriff
Posts: 3063
12
Mac IntelliJ IDE Python VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's an interesting question. I found the JavaDocs to be a bit unclear on this point, but with a few experiments, I've found that



seem to succeed immediately without trying to contact the host. However:



will try to connect to the remote host.

URLConnection has two timeout methods, one for setting the read timeout, and another for setting the connect timeout. So if you set:



and it can't connect within 10 seconds, it will throw a SocketTimeoutException. Try it!

Another option is setting the system properties: sun.net.client.defaultConnectTimeout and sun.net.client.defaultReadTimeout. I think that would work, but you probably have to set them as you start the JVM, i.e., with a -D parameter.
reply
    Bookmark Topic Watch Topic
  • New Topic