/* Set host configuration */
HostConfiguration hostConfiguration = new HostConfiguration();
/* Set connection manager parameters */
HttpConnectionManagerParams connectionManagerParams = new HttpConnectionManagerParams();
connectionManagerParams.setConnectionTimeout(config.getConnectionTimeout());
connectionManagerParams.setSoTimeout(config.getSocketTimeout());
connectionManagerParams.setStaleCheckingEnabled(true);
connectionManagerParams.setTcpNoDelay(true);
connectionManagerParams.setMaxTotalConnections(config.getMaxConnections());
connectionManagerParams.setMaxConnectionsPerHost(hostConfiguration, config.getMaxConnections());
int socketSendBufferSizeHint = config.getSocketBufferSizeHints()[0];
if (socketSendBufferSizeHint > 0) {
connectionManagerParams.setSendBufferSize(socketSendBufferSizeHint);
}
int socketReceiveBufferSizeHint = config.getSocketBufferSizeHints()[1];
if (socketReceiveBufferSizeHint > 0) {
connectionManagerParams.setReceiveBufferSize(socketReceiveBufferSizeHint);
}
/* Set connection manager */
MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
connectionManager.setParams(connectionManagerParams);