引用:
a實驗環境如果設為true則tomcat自動檢查恢復重新利用 沒有正常關閉的Connection (默認是false)
<parameter>
<name>removeAbandoned</name>
<value>true</value>
</parameter>
b設定連接在多少秒內被認為是放棄的連接 即可進行恢復利用
<parameter>
<name>removeAbandonedTimeout</name>
<value></value>
</parameter>
c輸出回收的日志 可以詳細打印出異常從而發現是在那裡發生了洩漏
<parameter>
<name>logAbandoned</name>
<value>true</value>
</parameter>
代碼如下
<parameter>
<name>maxActive</name>
<value>
</parameter>
<parameter>
<name>maxIdle</name>
<value>
</parameter>
<parameter>
<name>maxWait</name>
<value>
</parameter>
<parameter>
<name>removeAbandoned</name>
<value>true</value>
</parameter>
<parameter>
<name>removeAbandonedTimeout</name>
<value>
</parameter>
<parameter>
<name>logAbandoned</name>
<value>true</value>
</parameter>使用如下代碼進行實驗(每一次不關閉連接)
try {
Connection con = getJdbcDAO()
ResultSet rs = con
while (rs
System
}
} catch (SQLException e) {
e
}
當該連續執行
: : [org hibernate util JDBCExceptionReporter] [WARN] SQL Error: SQLState: null
: : [org hibernate util JDBCExceptionReporter] [ERROR] Cannot get a connection pool exhausted
: : [org hibernate util JDBCExceptionReporter] [WARN] SQL Error: SQLState: null
: : [org hibernate util JDBCExceptionReporter] [ERROR] Cannot get a connection pool exhausted
根據如下腳本查數據庫連接
declare cur_spid cursor
for
select spid from sysprocesses where ipaddr= and program_name <> SQL_Advantage
go
declare @spid Integer
open cur_spid
fetch cur_spid into @spid
while @@sqlstatus=
begin
print % ! @spid
dbcc traceon( )
dbcc sqltext(@spid )
fetch cur_spid into @spid
end
close cur_spid
![](http://tw.wingwit.com/Article/UploadFiles/201311/2013112320083836.gif)
得到類似如下的五條記錄
引用:
如果繼續執行該代碼
DBCC execution completedIf DBCC printed error messages contact a user with System Administrator (SA) role
SQL Text: select * from K_MSB_MSPBXX
DBCC execution completedIf DBCC printed error messages contact a user with System Administrator (SA) role
DBCP object created如果時間超過removeAbandonedTimeout設置的時間: : by the following code was never closed:
javalang Exception
at monsdbcp AbandonedTrace init(AbandonedTrace java: )
at monsdbcp AbandonedTrace <init>(AbandonedTrace java: )
at monsdbcp DelegatingResultSet <init>(DelegatingResultSet java: )
at monsdbcp DelegatingResultSet wrapResultSet(DelegatingResultSet java: )
at monsdbcp DelegatingStatement executeQuery(DelegatingStatement java: )
at comthunisoft fy spxt SpxtBaseLogic createPbxx(SpxtBaseLogic java: )
然後同樣的java代碼
因為大興實際環境還是出現連接池滿的問題(基本上兩天報一次)
From:http://tw.wingwit.com/Article/program/Java/ky/201311/28004.html