線上環境資料庫連接逾時原因

來源:互聯網
上載者:User

標籤:

查看線上日誌發現了如下的異常:

ERROR 500.jsp -

Error querying database.  Cause: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was 31,680,464 milliseconds ago.  The last packet sent successfully to the server was 31,680,469 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.

線上伺服器wait_timeout的值為:

select @@wait_timeout;

+----------------+

| @@wait_timeout |

+----------------+

|           7200 |

+----------------+

即兩個小時內沒有串連的話,伺服器會斷掉串連。等這時有請求過來的話,請求池會分配一中斷的串連,於是報了如上的異常。

經搜尋可以在串連池中添加一些額外的配置來避免此問題,如DBCP:

<!-- 配置間隔多久才進行一次檢測,檢測需要關閉的空閑串連,單位是毫秒 -->

 <property name="timeBetweenEvictionRunsMillis" value="60000" />

 <property name="validationQuery" value="SELECT ‘x‘" />

 <property name="testWhileIdle" value="true" />

線上環境資料庫連接逾時原因

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.