11

My implementation of httpclient occasionally throws an exception when calling doGetConnection(). However, I have the following timeout set

_moHttpClient.setHttpConnectionFactoryTimeout(30000);

it looks almost like my timeout is not being picked up. Is there anywhere else I need to set a timeout to ensure this behaviour does not re-occur

Eddie
  • 53,828
  • 22
  • 125
  • 145

3 Answers3

10

What exception are you getting thrown ?

Don't forget you have two timeouts to change/check. From HttpConnectionParams

setConnectionTimeout()
setSoTimeout()

so you can control how long you wait for a connection to the server, and how long operations on the socket can take before timing out.

Brian Agnew
  • 268,207
  • 37
  • 334
  • 440
  • Docs seem to indicate that SO_TIMEOUT is max allowed time for the server to be unresponsive since the last received TCP packet. http://hc.apache.org/httpcomponents-core-ga/httpcore/apidocs/org/apache/http/params/CoreConnectionPNames.html#SO_TIMEOUT – Boris B. Jan 27 '14 at 19:58
7
    HttpConnectionManagerParams cmparams = new HttpConnectionManagerParams();
    cmparams.setSoTimeout(10000);
    cmparams.setTcpNoDelay(true);
    HttpConnectionManager manager = new SimpleHttpConnectionManager();
    manager.setParams(cmparams);
    params = new HttpClientParams();
    params.setSoTimeout(5000);
    client = new HttpClient(params, manager);

I wonder why I have two different SoTimeouts set. Maybe I was trying to find out which one was actually active, as I had the same problems as you when I used it.

The above is in live code at our place right now, but I cannot say whether it works because it's correct, or because providence is smiling down on me (and the other end is usually always available).

JeeBee
  • 17,476
  • 5
  • 50
  • 60
4

cmparams.setSoTimeout(10000);

This one is for all HttpClient by default.

params.setSoTimeout(5000);

And this one is for a particular httpclient.