【Tomcat】tomcat報連接超時錯誤


程序一直報這個錯誤

[getui-server][ERROR] [2016-03-17 10:50:00] getui.task.HftMongoInfoTask.execute(137) | --HftMongoInfoTask-error-org.springframework.dao.RecoverableDataAccessException: PreparedStatementCallback; SQL [select mid from test_info where cid = 9]; Communications link failure

The last packet successfully received from the server was 250,825 milliseconds ago.  The last packet sent successfully to the server was 0 milliseconds ago.; nested exception is com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

The last packet successfully received from the server was 250,825 milliseconds ago.  The last packet sent successfully to the server was 0 milliseconds ago.

百度搜了很多,很多人都遇到過這個錯誤,大部分都是使用連接池方式時才會出現這個問題,短連接應該很難出現這個問題。這個問題的原因:

MySQL服務器默認的“wait_timeout”是28800秒即8小時,意味着如果一個連接的空閑時間超過8個小時,MySQL將自動斷開該連接,而連接池卻認為該連接還是有效的(因為並未校驗連接的有效性),當應用申請使用該連接時,就會導致上面的報錯。

1.按照錯誤的提示,可以在JDBC URL中使用autoReconnect屬性,實際測試時使用了autoReconnect=true&failOverReadOnly=false,不過並未起作用,使用的是5.1版本,可能真像網上所說的只對4之前的版本有效。

2.沒辦法,只能修改MySQL的參數了,wait_timeout最大為31536000即1年,在my.cnf中加入:

[mysqld]

wait_timeout=31536000

interactive_timeout=31536000

3.以上方法試過了,都不行。

結果是我的連接池問題,dbcp鏈接數據庫超時,增加一個自定檢測釋放,就可以了。

下面是兩個我解決問題的鏈接,希望對遇到這個問題的伙伴有幫助。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM