Solved

How to implement a HttpUrlConnection timeout with jdk1.4

Posted on 2006-06-23
6
988 Views
Last Modified: 2007-12-19
Hello,

I have an application that check a list of urls (by getting the response code sent by the server), but sometimes the application runs very slowly due to large timeout delay when getting the server response. I need to implement a connection timeout via a timer and i would be pleased to see some code sample for that.
I am using jdk1.4.1.

Thanks a lot (it is very very urgent)
0
Comment
Question by:psandjon
6 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 125 total points
ID: 16972690
Set VM properties

sun.net.client.defaultConnectTimeout (default: -1)
sun.net.client.defaultReadTimeout (default: -1)

See

http://java.sun.com/j2se/1.4.2/docs/guide/net/properties.html
0
 
LVL 92

Assisted Solution

by:objects
objects earned 125 total points
ID: 16973256
0
 
LVL 14

Assisted Solution

by:hoomanv
hoomanv earned 125 total points
ID: 16974109
0
 
LVL 2

Assisted Solution

by:RoyalNepal
RoyalNepal earned 125 total points
ID: 17092638
If you use J2SE 1.4.x then one possible workaround is to set the sun.net.client.defaultReadTimeout and sun.net.client.defaultConnectTimeout system properties. These properties specify the default timeout (in ms) for reads and connect timeouts use in the Sun implementation of the protocol handlers.


You could implement your own http client to make the requests and enable SO_TIMEOUT of the sockets with the desired timeout (it isn't very complicated).
However, if you don't feel like building your own you can use somebody else's implementation. One component that implements the clien side of the HTTP protocol is the Jakarta Commons HttpClient (http://jakarta.apache.org/commons/httpclient/). It allows you to set the timeout for the read operations.

I hope I helped
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…

937 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

4 Experts available now in Live!

Get 1:1 Help Now