我越來越可怕的MySQL JDBC陳舊連接異常:失效連接,validationQuery不能解決
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operations allowed after connection closed.
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was 243,263,541 milliseconds ago. The last packet sent successfully to the server was 243,263,541 milliseconds ago. is longer than the server configured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem.
好像所有人都認爲這是通過使用validationQuery + testOnBorrow固定的,但是這並不是解決問題。
我使用以下軟件 的MySQL 5.1.41-3ubuntu12.10 連接器/ J 5.1.18 的Tomcat 6.0.24
這裏是如何連接在server.xml中定義,我們使用tomcat-dbcp來連接連接。
<Resource
auth="Container"
driverClassName="com.mysql.jdbc.Driver"
factory="org.apache.commons.dbcp.BasicDataSourceFactory"
logAbandoned="true"
maxActive="75"
maxIdle="20"
maxWait="10000"
name="jdbc/jndiname"
password="password"
removeAbandoned="true"
removeAbandonedTimeout="60"
validationQuery="/* ping */SELECT 1"
testOnBorrow="true"
testOnReturn="true"
timeBetweenEvictionRunsMillis="10000"
testWhileIdle="true"
scope="Shareable"
type="javax.sql.DataSource"
url="jdbc:mysql://host:3306/schema"
username="username" />
在什麼情況下你會得到那些陳舊的連接異常?你是否發送了一個實時查詢,這就是結果?你是否像查詢那樣創建了JDBC連接,還是從連接池中抓取它們? – technocrat 2012-01-30 19:59:27
每天早上當用戶首次連接到我們的Web應用程序時,會發生連接異常。連接來自Tomcat-DBCP池。我們可以通過每天重新啓動Tomcat來解決問題,但這隻能掩蓋真正的問題。 – user763648 2012-01-30 20:06:19
重新啓動Tomcat時,所做的只是使連接池自行備份。你相信這個修復會被tomcat配置,mysql配置或tomcat-dbcp池代碼改變嗎?只是讓我知道尋找答案的方向。 – technocrat 2012-01-30 22:47:08