2015-09-26 97 views
1

我在org.apache.tomcat.jdbc.pool.PoolProperties上添加了setMaxActive(8)。每次數據庫重新啓動時,應用程序都將無法使用,因爲建立的連接仍然存在。我得到以下錯誤:JDBC連接池:數據庫重新啓動後連接不再循環

org.postgresql.util.PSQLException: This connection has been closed

我使用的池無濟於事一些其他設置試過......

感謝您的幫助!

+0

捕獲該異常並重新創建在池中 –

回答

1

使用validationQuery屬性,它將在返回連接之前檢查連接是否有效。

編號:Tomcat 6 JDBC Connection Pool

該屬性可以用最新的Tomcat版本。

1

看看這個鏈接:

Postgres connection has been closed error in Spring Boot

Very valid question and this problem is usually faced by many. The exception generally occurs, when network connection is lost between pool and database (most of the time due to restart). Looking at the stack trace you have specified, it is quite clear that you are using jdbc pool to get the connection. JDBC pool has options to fine-tune various connection pool settings and log details about whats going on inside pool.

You can refer to to detailed Apache documentation on pool configuration to specify abandon timeout

Check for removeAbandoned, removeAbandonedTimeout, logAbandoned parameters 

Additionally you can make use of additional properties to further tighten the validation

Use testXXX and validationQuery for connection validity. 

我自己的$ 0.02:使用這兩個參數:

validationQuery=<TEST SQL> 
testOnBorrow=true 
+0

謝謝你的連接,我嘗試使用removeAbandoned,這沒有幫助,我會嘗試validationQuery和testOnBorrow。 – user4493152