<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

    之前做了一個web項目的時候,好好的網站第二天總是會提示using the Connector/J connection property 'autoReconnect=true' to avoid this problem.  這樣的錯誤

    1com.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就會自動斷開連接

    第一種解決方案是在 connection url中加參數: autoReconnect=true

    1jdbc.url=jdbc:mysql://ipaddress:3306/database?autoReconnect=true&amp;autoReconnectForPools=true
    第二種如果使用hibernate的時候做如下配置
    1<property name="connection.autoReconnect">true</property>
    2<property name="connection.autoReconnectForPools">true</property>
    3<property name="connection.is-connection-validation-required">true</property>
    如果使用了c3p0做如下配置
    1<property name="hibernate.c3p0.acquire_increment">1</property>
    2<property name="hibernate.c3p0.idle_test_period">0</property>
    3<property name="hibernate.c3p0.timeout">0</property>
    4<property name="hibernate.c3p0.validate">true</property>
    第三種方法如下:

    大部分都是使用連接池方式時才會出現這個問題,短連接應該很難出現這個問題。這個問題的原因:

    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中加入:

    1wait_timeout=31536000
    2 
    3interactive_timeout=31536000

    重啟生效,需要同時修改這兩個參數。

    參考文檔: http://aayy520.blog.163.com/blog/static/23182260201102994534777/

    總結一下,這種問題主要是使用了連接池沒有識別出過期的鏈接,解決方案就是數據庫連接加一個autoReconnect的參數?;蛘呤褂每蚣艿囊恍﹨祦砜刂啤?/span>

    posted on 2014-04-28 13:32 ivaneeo 閱讀(478) 評論(0)  編輯  收藏 所屬分類: java魔力
    主站蜘蛛池模板: 亚洲免费电影网站| 天天影视色香欲综合免费| 国产成人亚洲综合一区| 亚洲成AV人片在线观看WWW| 免费人成在线观看网站视频 | 麻豆国产精品入口免费观看| 特级无码毛片免费视频尤物| 一级毛片免费在线| 国产亚洲视频在线播放大全| 亚洲色偷偷色噜噜狠狠99| 亚洲成人免费在线观看| 久久精品国产亚洲av麻豆小说| 国产亚洲色视频在线| 免费国产美女爽到喷出水来视频| 欧美男同gv免费网站观看| 亚洲精品视频免费在线观看| 久久黄色免费网站| 免费精品一区二区三区第35| 中文精品人人永久免费| 久久久久久毛片免费看| 天堂亚洲免费视频| 一个人看的在线免费视频| 一级毛片免费全部播放| 免费无毒a网站在线观看| 免费的黄网站男人的天堂| 国产精品亚洲专区在线播放| 久久久久久亚洲精品无码 | 国产精品深夜福利免费观看| 四虎永久在线精品免费网址 | 亚洲国产品综合人成综合网站| 亚洲影院在线观看| 亚洲精品美女在线观看播放| 亚洲综合网美国十次| 亚洲伊人久久大香线蕉在观| 国产精品亚洲精品| 亚洲精品无码久久久久YW| 99亚洲男女激情在线观看| 免费无码婬片aaa直播表情| 一级一级毛片免费播放| 国产日韩AV免费无码一区二区 | 久久亚洲国产精品五月天婷|