Solved

How to implement a HttpUrlConnection timeout with jdk1.4

Posted on 2006-06-23
6
1,014 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying 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

Suggested Solutions

Title # Comments Views Activity
jsp login check 12 67
Convert from a json string array to a Java object 3 81
CSV file parsing thru Java 13 54
Overriding a method 3 15
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
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 …
This video teaches viewers about errors in exception handling.
Suggested Courses

752 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