現(xiàn)狀:在我們的項目中使用了Ofbiz2.1,TransactionFactory配置為JotmFactory,數(shù)據(jù)庫是Oracle9i,lifeTime設(shè)置為120000(2分鐘)在大并發(fā)測試的時候發(fā)現(xiàn)經(jīng)常Closed Connection的異常。
原因:Oracle數(shù)據(jù)庫會檢查physical connection的idle時間和使用次數(shù)并關(guān)閉長時間idle的physical connection,如果應用對從連接池中
獲取的connection不進行檢查,或者連接池仔返回可用連接之前不進行檢查,在使用過程中就會Closed Connection的異常。大多數(shù)數(shù)據(jù)庫都會檢查physical connection的idle時間。
解決辦法:調(diào)用StandardPoolDataSource或者StandardXAPoolDataSource的setCheckLevelObject(int)方法設(shè)置連接檢查級別,參數(shù)取值如下:
-
0:不檢查
-
1:對unlocked池中獲取的連接進行Closed檢查
-
2:對unlocked池中獲取的連接進行sql測試,需要設(shè)置setJdbcTestStmt(Test SQL)
-
3:對所有unlocked池中的連接進行Closed檢查
-
4:對所有unloked池中的連接進行測試,需要設(shè)置setJdbcTestStmt(Test SQL)