服務器上用 HttpClient 遠程調用另一臺服務器的一些資源,但是用 netstat 查看經常出現了很多的 CLOSE_WAIT 的連接,最后追查原因,是因為 HttpClient 的 method.releaseConnection() 并不是強制釋放連接,為了減小連接數,使用了如下解決方案。在 HttpClient 完成請求后的 finally 塊里面這么寫。
} finally {
if (method != null) {
try {
method.releaseConnection();
} catch (Exception e) {
logger.error("-------> Release HTTP connection exception:", e);
}
}
if (client != null) {
try {
((SimpleHttpConnectionManager) client.getHttpConnectionManager()).shutdown();
} catch (Exception e) {
logger.error("-------> Close HTTP connection exception:", e);
}
client = null;
}
}
原文:
http://www.steadyxp.com/archives/832.html
posted on 2009-02-23 13:49
steady 閱讀(4398)
評論(0) 編輯 收藏 所屬分類:
Java