hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Roland Weber <http-as...@dubioso.net>
Subject Re: Recovering a connection from an unresponsive host
Date Wed, 08 Nov 2006 17:33:39 GMT
Hi Graeme,

> I've attempted this with both the stable (3.0.1) and current (3.1beta1)
> version of the httpclient binaries.
> 
> I have been trying to determine how to correctly set the timeout
> parameters in order to limit the connection time and force the code
> below to complete within a maximum amount of time.

That's impossible. The timeout parameters apply to individual operations
performed as part of method execution. You cannot set an overall timeout.
You have to start an extra thread to achieve that effect.

> I have also attempted to run similar code in its own thread and using a
> separate timer, call httpget.abort(); httpget.releaseConnection(). This
> doesn't change the behavour of the program: the thread still hangs for 75s.

Sounds like a known issue which we can't solve in HttpClient 3.x:
https://issues.apache.org/jira/browse/HTTPCLIENT-475

> Am I incorrectly interpreting the use of the http.socket.timeout
> parameter?

As Olaf suggested, try setting the timeout on the connection manager
instead of the method.

> Is there an alternate way to guarantee that the thread never
> spends more than a certain amount of time in the
> httpclient.executeMethod() function?

There's one rather rude way to enforce the timeout. Instead of starting
a timer thread that tries to interrupt the main one, start a worker thread
that performs the actual operation. In the main thread, use Object.wait(ms)
to synchronize with the worker thread, try to terminate the worker if you
hit the timeout. Even if the worker thread is not correctly interrupted
due to the problem mentioned above, your main thread can continue. The
connection remains blocked until the worker thread hits it's internal
timeout, though.

hope that helps,
  Roland


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org


Mime
View raw message