Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1050
  • Last Modified:

How to implement a HttpUrlConnection timeout with jdk1.4

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
psandjon
Asked:
psandjon
4 Solutions
 
CEHJCommented:
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
 
RoyalNepalCommented:
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now