Apache HttpClient allows to configure two timeouts: ConnectionTimeout and SoTimeout
This is how people typically create a general purpose HttpClient instance:
PoolingClientConnectionManager conman = new PoolingClientConnectionManager();
conman.setMaxTotal(200);
conman.setDefaultMaxPerRoute(100);
HttpClient httpClient = new DefaultHttpClient(conman);
HttpConnectionParams.setConnectionTimeout(httpClient.getParams(), 1000);
HttpConnectionParams.setSoTimeout(httpClient.getParams(), 1000);
The ConnectionTimeout param is tricky, it covers two scenarious:
HttpClient may throw
org.apache.http.conn.ConnectTimeoutException: Connect to example.com timed out- if it wasn't able to establish an underlying TCP connectionAlso it may throw
org.apache.http.conn.ConnectionPoolTimeoutException: Timeout waiting for connection from pool- when the connection pool is full and it wasn't able to get a new connection from pool within this period of time
I have two questions around this:
1) Is there a reason why these two actually different timeouts were combined under single ConnectionTimeout param.
There is no way for example to wait for available connection from pool for 10sec, but keep socket-connection-timeout to 1sec
2) What are recommended values for ConnectionTimeout and SoTimeout for general purpose scenario?
DefaultHttpClientis deprecated now, andHttpClient 4.5has 3 methods to configure timeouts:setConnectTimeout, setSocketTimeout, setConnectionRequestTimeout- Vladimir Sorokin