Solved

How to implement a HttpUrlConnection timeout with jdk1.4

Posted on 2006-06-23
6
1,007 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

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…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This video teaches viewers about errors in exception handling.

820 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