URLConnection timeout

I have HttpsURLConnection connection.

When using 'inputStream = connection.getInputStream();' it waits too long.

How can I set an acceptable timeout time?

Rgds, Ales
LVL 3
drjustinAsked:
Who is Participating?
 
CEHJConnect With a Mentor Commented:
(5 seconds)

System.setProperty("sun.net.client.defaultConnectTimeout", "5000");
System.setProperty("sun.net.client.defaultReadTimeout", "5000");
0
 
CEHJCommented:
0
 
drjustinAuthor Commented:
What happens then when timeout exceeds?
Is exception thrown?
0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

 
bloodredsunCommented:
There is also the method:
public void setReadTimeout(int timeout)

where timout is milliseconds, but this is java 1.5
0
 
CEHJCommented:
Yes, so you need to handle it
0
 
bloodredsunCommented:
In the above method a SocketTimeoutException is raised, for the normal method I believe an IOException is raised.
0
 
CEHJCommented:
:-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.