<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    ivaneeo's blog

    自由的力量,自由的生活。

      BlogJava :: 首頁 :: 聯系 :: 聚合  :: 管理
      669 Posts :: 0 Stories :: 64 Comments :: 0 Trackbacks

    com.mysql.jdbc.CommunicationsException: The last packet successfully received from the server was58129 seconds ago.The last packet sent successfully to the server was 58129 seconds ago, which 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.

     

    查了一下,原來是mysql超時設置的問題
    如果連接閑置8小時 (8小時內沒有進行數據庫操作), mysql就會自動斷開連接, 要重啟tomcat.

     

     

    解決辦法:

     

     

        一種. 如果不用hibernate的話, 則在 connection url中加參數: autoReconnect=true

    jdbc.url=jdbc:mysql://ipaddress:3306/database?autoReconnect=true&amp;autoReconnectForPools=true

     


        二種。用hibernate的話, 加如下屬性:
            <property name="connection.autoReconnect">true</property>
            <property name="connection.autoReconnectForPools">true</property>
            <property name="connection.is-connection-validation-required">true</property>

     


        三。要是還用c3p0連接池:
            <property name="hibernate.c3p0.acquire_increment">1</property>
            <property name="hibernate.c3p0.idle_test_period">0</property>
            <property name="hibernate.c3p0.timeout">0</property>
            <property name="hibernate.c3p0.validate">true</property>

     

     

     四。最不好的解決方案

     

    使用Connector/J連接MySQL數據庫,程序運行較長時間后就會報以下錯誤:

    Communications link failure,The last packet successfully received from the server was *** millisecond ago.The last packet successfully sent to the server was ***  millisecond ago。

    其中錯誤還會提示你修改wait_timeout或是使用Connector/J的autoReconnect屬性避免該錯誤。

    后來查了一些資料,才發現遇到這個問題的人還真不少,大部分都是使用連接池方式時才會出現這個問題,短連接應該很難出現這個問題。這個問題的原因:

    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

    重啟生效,需要同時修改這兩個參數
    posted on 2012-11-06 16:29 ivaneeo 閱讀(4104) 評論(0)  編輯  收藏 所屬分類: bi(商務智能)
    主站蜘蛛池模板: 国产精品手机在线亚洲| 国产亚洲精aa在线看| 狠狠躁狠狠爱免费视频无码| 日本v片免费一区二区三区 | 4hu四虎免费影院www| 又粗又黄又猛又爽大片免费| 立即播放免费毛片一级| 亚洲精品乱码久久久久久不卡| 中文字幕不卡免费高清视频| 久久久www成人免费毛片| 亚洲中文字幕无码一去台湾 | 亚洲国产aⅴ成人精品无吗| 中文字幕的电影免费网站| 国外亚洲成AV人片在线观看| 亚洲精品无码成人片久久不卡| 久久久久国产免费| 亚洲精品成人网久久久久久| 国产精品免费看久久久香蕉 | 好大好硬好爽免费视频| 亚洲AV无码专区国产乱码不卡| 免费又黄又爽又猛的毛片| 国产99精品一区二区三区免费| 亚洲av综合avav中文| 6080午夜一级毛片免费看6080夜福利| 亚洲一区二区三区高清视频| 四虎国产精品免费视| 亚洲夂夂婷婷色拍WW47| 国产成人精品免费视频网页大全| 亚洲av无码一区二区乱子伦as| 2021在线永久免费视频| 亚洲av无码一区二区三区人妖| 中文字幕亚洲日韩无线码| fc2免费人成在线| 亚洲熟妇无码久久精品| 日本免费大黄在线观看| 成人亚洲国产va天堂| AV在线播放日韩亚洲欧| 久久WWW免费人成—看片| 亚洲女人初试黑人巨高清| 国产h肉在线视频免费观看| 特级毛片全部免费播放|