1. 問題描述
Web程序在tomcat剛開始運(yùn)行時(shí)速度很快,但過一段時(shí)間后發(fā)現(xiàn)速度變得很慢。
檢查日志輸出,發(fā)現(xiàn)異常如下:
org.apache.commons.dbcp.SQLNestedException:
Cannot get a connection, pool exhausted,
cause:
java.util.NoSuchElementException: Timeout waiting for idle
object
同時(shí)在SQLServer事件探查器中發(fā)現(xiàn),每執(zhí)行一次sql語句都要產(chǎn)生Audit login事件,語句執(zhí)行后產(chǎn)生
Audit
logout事件。說明每一次tomcat都是重新打開新的連接。
Web程序在tomcat剛開始運(yùn)行時(shí)速度很快,但過一段時(shí)間后發(fā)現(xiàn)速度變得很慢。
檢查日志輸出,發(fā)現(xiàn)異常如下:
org.apache.commons.dbcp.SQLNestedException:
Cannot get a connection, pool exhausted,
cause:
java.util.NoSuchElementException: Timeout waiting for idle
object
同時(shí)在SQLServer事件探查器中發(fā)現(xiàn),每執(zhí)行一次sql語句都要產(chǎn)生Audit login事件,語句執(zhí)行后產(chǎn)生
Audit
logout事件。說明每一次tomcat都是重新打開新的連接。
2. 問題解決
tomcat
的數(shù)據(jù)源定義提供了三個(gè)參數(shù):
a. 如果設(shè)為true則tomcat自動(dòng)檢查恢復(fù)重新利用,沒有正常關(guān)閉的Connection.(默認(rèn)是false)
<parameter>
<name>removeAbandoned</name>
<value>true</value>
</parameter>
b.
設(shè)定連接在多少秒內(nèi)被認(rèn)為是放棄的連接,即可進(jìn)行恢復(fù)利用。
<parameter>
<name>removeAbandonedTimeout</name>
<value>60</value>
</parameter>
c.
輸出回收的日志,可以詳細(xì)打印出異常從而發(fā)現(xiàn)是在那里發(fā)生了泄漏
<parameter>
<name>logAbandoned</name>
<value>true</value>
</parameter>
比如:<Resource logAbandoned="true" removeAbandonedTimeout="60" removeAbandoned="true"
tomcat
的數(shù)據(jù)源定義提供了三個(gè)參數(shù):
a. 如果設(shè)為true則tomcat自動(dòng)檢查恢復(fù)重新利用,沒有正常關(guān)閉的Connection.(默認(rèn)是false)
<parameter>
<name>removeAbandoned</name>
<value>true</value>
</parameter>
b.
設(shè)定連接在多少秒內(nèi)被認(rèn)為是放棄的連接,即可進(jìn)行恢復(fù)利用。
<parameter>
<name>removeAbandonedTimeout</name>
<value>60</value>
</parameter>
c.
輸出回收的日志,可以詳細(xì)打印出異常從而發(fā)現(xiàn)是在那里發(fā)生了泄漏
<parameter>
<name>logAbandoned</name>
<value>true</value>
</parameter>
比如:<Resource logAbandoned="true" removeAbandonedTimeout="60" removeAbandoned="true"