Solved

How to implement a HttpUrlConnection timeout with jdk1.4

Posted on 2006-06-23
6
985 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

757 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

25 Experts available now in Live!

Get 1:1 Help Now