服務(wù)器上用 HttpClient 遠(yuǎn)程調(diào)用另一臺服務(wù)器的一些資源,但是用 netstat 查看經(jīng)常出現(xiàn)了很多的 CLOSE_WAIT 的連接,最后追查原因,是因?yàn)?HttpClient 的 method.releaseConnection() 并不是強(qiáng)制釋放連接,為了減小連接數(shù),使用了如下解決方案。在 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 閱讀(4402)
評論(0) 編輯 收藏 所屬分類:
Java