apache HttpClient API 中的 setConnectionTimeout 、setSoTimeout 和 “http.connection-manager.timeout” 有什么区别?
2022-09-01 01:46:57
三者有什么区别(标记为注释):
MultiThreadedHttpConnectionManager connManag = new MultiThreadedHttpConnectionManager();
HttpConnectionManagerParams managParams = connManag.getParams();
managParams.setConnectionTimeout(connectiontimeout); // 1
managParams.setSoTimeout(sotimeout); //2
HttpMethodBase baseMethod = null;
try {
HttpClient client = new HttpClient(connManag);
client.getParams().setParameter("http.connection-manager.timeout", poolTimeout); //3
baseMethod = new GetMethod(…);
int statusCode = client.executeMethod(…);
…
}
catch (ConnectTimeoutException cte ){
//Took too long to connect to remote host
}
catch (SocketTimeoutException ste){
//Remote host didn’t respond in time
}
catch (Exception se){
//Some other error occurred
}
finally {
if (baseMethod != null)
baseMethod.releaseConnection();
}
1. setConnectionTimeout
- 如果它确定建立连接之前的超时。
2. setSoTimeout
- 如果它决定了两个连续数据包之间的不活动时间或时间差,
那么下面的一个是做什么的:
3. "http.connection-manager.timeout"