HttpURLConnection timeout? - Java

This is a discussion on HttpURLConnection timeout? - Java ; Hi, Is it possible to set a timeout when opening a connection to an HttpURLConnection? For example, is it possible to make the connection call and limit it to 5 seconds before a response is generated? That is, I don't ...

+ Reply to Thread
Results 1 to 3 of 3

HttpURLConnection timeout?

  1. Default HttpURLConnection timeout?

    Hi,

    Is it possible to set a timeout when opening a connection to an
    HttpURLConnection?

    For example, is it possible to make the connection call and limit it to 5
    seconds before a response is generated?

    That is, I don't want to have to wait for the "default" timeout.

    Thanks for any info.

    Jack



  2. Default Re: HttpURLConnection timeout?

    Jack wrote:
    > Hi,
    >
    > Is it possible to set a timeout when opening a connection to an
    > HttpURLConnection?
    >
    > For example, is it possible to make the connection call and limit it to 5
    > seconds before a response is generated?
    >
    > That is, I don't want to have to wait for the "default" timeout.

    [snip]

    You can't do this using Sun's classes unless you use a "private"
    property setting. Unfortunately, the setting is not guaranteed to
    remain the same (or remain at all).

    I've just been working on a similar task and used the
    Commons-HTTPClient[1] from Apache. It allows you to specify both a
    connection timeout and also a timeout when reading the response. It
    works superbly!

    [1] http://jakarta.apache.org/commons/httpclient/

    --
    Dave Ockwell-Jenner
    Solar Nexus Solutions
    http://www.solar-nexus.com/

  3. Default Re: HttpURLConnection timeout?

    Dave Ockwell-Jenner wrote:
    > Jack wrote:
    >
    >> Hi,
    >>
    >> Is it possible to set a timeout when opening a connection to an
    >> HttpURLConnection?
    >>
    >> For example, is it possible to make the connection call and limit it to 5
    >> seconds before a response is generated?
    >>
    >> That is, I don't want to have to wait for the "default" timeout.

    >
    > [snip]
    >
    > You can't do this using Sun's classes unless you use a "private"
    > property setting. Unfortunately, the setting is not guaranteed to
    > remain the same (or remain at all).
    >
    > I've just been working on a similar task and used the
    > Commons-HTTPClient[1] from Apache. It allows you to specify both a
    > connection timeout and also a timeout when reading the response. It
    > works superbly!
    >
    > [1] http://jakarta.apache.org/commons/httpclient/


    Actually Sun has added this in Java 1.5. See the java.net.URLConnection
    setConnectionTimeout() and setReadTimeout() methods. If you need
    to use an earlier version of Java then the Jakarta HTTPClient package
    works great.

+ Reply to Thread

Similar Threads

  1. HttpURLConnection locks up on connect()
    By Application Development in forum Java
    Replies: 5
    Last Post: 01-23-2007, 11:12 PM
  2. NETREXX and HttpURLConnection class
    By Application Development in forum REXX
    Replies: 1
    Last Post: 10-08-2005, 02:28 AM
  3. how to set an http request header used in HttpURLConnection ?
    By Application Development in forum Java
    Replies: 5
    Last Post: 05-20-2004, 06:28 AM
  4. Replies: 1
    Last Post: 02-11-2004, 11:02 PM
  5. Replies: 1
    Last Post: 01-03-2004, 04:17 PM