Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Apache HttpClient - Timeout issue

807588Jan 19 2009 — edited Feb 12 2009
Hi,

I'm using HttpClient 3.1 to connect to a server.
I've set both the connection timeout and the socket timeout.
I set the connection timeout in the HttpConnectionManager (later set in HttpClient) like this:
			MultiThreadedHttpConnectionManager cm = new MultiThreadedHttpConnectionManager();
			//connection timeout - same value as for socket timeout (set in the PostMethod - see below))
			cm.getParams().setConnectionTimeout(Integer.parseInt(getProperty(MADS_AD_TIMEOUT)));
			//set HttpConnectionManager in HttpClient
			madsClient.setHttpConnectionManager(cm);
I set the sockettimeout in the PostMethod class like this:
			//retry and socket timeout settings (result = an instance of PostMethod)
			result.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(1, false));
			//socket timeout (connection timeout already set in HttpClient)
			result.getParams().setSoTimeout(Integer.parseInt(getProperty(MADS_AD_TIMEOUT)));
At times (when the server we connect to is slow on response?) the requests still wait for a much longer time than the timeout we use (500 ms).
A SocketTimeout/ConnectionTimeout-exception is thrown, but this might take a very long time (48 seconds is a recent example). We measure the time in
our code.

Any idea what might cause this problem?

/best regards, HÃ¥kan Jacobsson, System developer in Stockholm, Sweden.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 12 2009
Added on Jan 19 2009
2 comments
1,428 views