client.setConnectionTimeout(connectionTimeout);
client.setTimeout(timeout);
client.setHttpConnectionFactoryTimeout(httpConnectionFactoryTimeout);
尽管上述三个方法已经过时,这里只是说明一下情况,不妨碍理解。第一个是连接超时,就是TCP三次握手的连接超时。第二个是客户端读数据的超时,如果这个时间内还没有读到response的数据,那么超时,这个时候,相当于断开。第三个,求高手解释。这三者值,个人认为: connectionTimeout(2秒足矣) < timeout (20秒) < httpConnectionFactoryTimeout (25秒)
client.setTimeout(timeout);
client.setHttpConnectionFactoryTimeout(httpConnectionFactoryTimeout);
尽管上述三个方法已经过时,这里只是说明一下情况,不妨碍理解。第一个是连接超时,就是TCP三次握手的连接超时。第二个是客户端读数据的超时,如果这个时间内还没有读到response的数据,那么超时,这个时候,相当于断开。第三个,求高手解释。这三者值,个人认为: connectionTimeout(2秒足矣) < timeout (20秒) < httpConnectionFactoryTimeout (25秒)
// Increase max total connection to 200
cm.setMaxTotal(200);
// Increase default max connection per route to 20
cm.setDefaultMaxPerRoute(20);
对应池里允许的最大连接数200,每个域名允许最多20个连接。假如你开30个连接同时访问一个域名下的url。那么其中有10个就要等待,因为池的设置已经不允许再创建连接了。必须等待其他已经连上的读取完归还到池里才行。