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

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

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

    ivaneeo's blog

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

      BlogJava :: 首頁(yè) :: 聯(lián)系 :: 聚合  :: 管理
      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.

     

    查了一下,原來(lái)是mysql超時(shí)設(shè)置的問(wèn)題
    如果連接閑置8小時(shí) (8小時(shí)內(nèi)沒(méi)有進(jìn)行數(shù)據(jù)庫(kù)操作), mysql就會(huì)自動(dòng)斷開(kāi)連接, 要重啟tomcat.

     

     

    解決辦法:

     

     

        一種. 如果不用hibernate的話, 則在 connection url中加參數(shù): 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數(shù)據(jù)庫(kù),程序運(yùn)行較長(zhǎng)時(shí)間后就會(huì)報(bào)以下錯(cuò)誤:

    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。

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

    后來(lái)查了一些資料,才發(fā)現(xiàn)遇到這個(gè)問(wèn)題的人還真不少,大部分都是使用連接池方式時(shí)才會(huì)出現(xiàn)這個(gè)問(wèn)題,短連接應(yīng)該很難出現(xiàn)這個(gè)問(wèn)題。這個(gè)問(wèn)題的原因:

    MySQL服務(wù)器默認(rèn)的“wait_timeout”是28800秒即8小時(shí),意味著如果一個(gè)連接的空閑時(shí)間超過(guò)8個(gè)小時(shí),MySQL將自動(dòng)斷開(kāi)該連接,而連接池卻認(rèn)為該連接還是有效的(因?yàn)椴⑽葱r?yàn)連接的有效性),當(dāng)應(yīng)用申請(qǐng)使用該連接時(shí),就會(huì)導(dǎo)致上面的報(bào)錯(cuò)。

    1.按照錯(cuò)誤的提示,可以在JDBC URL中使用autoReconnect屬性,實(shí)際測(cè)試時(shí)使用了autoReconnect=true& failOverReadOnly=false,不過(guò)并未起作用,使用的是5.1版本,可能真像網(wǎng)上所說(shuō)的只對(duì)4之前的版本有效。

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

    [mysqld]

    wait_timeout=31536000

    interactive_timeout=31536000

    重啟生效,需要同時(shí)修改這兩個(gè)參數(shù)
    posted on 2012-11-06 16:29 ivaneeo 閱讀(4103) 評(píng)論(0)  編輯  收藏 所屬分類: bi(商務(wù)智能)
    主站蜘蛛池模板: 亚洲毛片在线免费观看| 国产大陆亚洲精品国产| 成人黄动漫画免费网站视频| 久久久久久亚洲av无码蜜芽| 黑人大战亚洲人精品一区| 在线观看永久免费| 免费无毒a网站在线观看| 久久久亚洲精品无码| 天天看片天天爽_免费播放| 国产va免费观看| 日本亚洲色大成网站www久久 | 亚洲伊人久久大香线蕉啊| 日本一区二区三区日本免费| 久久99免费视频| 含羞草国产亚洲精品岁国产精品| 亚洲色大成网站www永久一区| 中文字幕无码不卡免费视频| 国产免费黄色无码视频| 国产亚洲精品影视在线| 亚洲国产成人片在线观看| 午夜一级毛片免费视频| 91香蕉国产线在线观看免费| 精品特级一级毛片免费观看| 亚洲综合久久成人69| 国产成人亚洲综合| 女人18毛片免费观看| 特级精品毛片免费观看| 四虎影视永久在线精品免费| 亚洲jjzzjjzz在线观看| 亚洲国产精品无码久久久蜜芽 | **aaaaa毛片免费| 亚洲免费一区二区| 亚洲欧美国产日韩av野草社区| 亚洲精品天天影视综合网| 国产精品xxxx国产喷水亚洲国产精品无码久久一区 | 美丽姑娘免费观看在线观看中文版| 99亚洲男女激情在线观看| 亚洲AV色吊丝无码| 久久久久亚洲AV成人片| 亚洲中文字幕无码不卡电影| 免费永久在线观看黄网站|