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

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

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

    我的Blog我做主^_^

    走向一條通往JAVA的不歸路...

      BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
      64 隨筆 :: 68 文章 :: 77 評論 :: 0 Trackbacks

    前一段時間朋友用hibernate+mysql整了一個應用,出現tomcat放一夜,mysql連接出現錯誤的情況,具體的錯誤信息忘記了。

    在網上查找一下,找到了這個帖子,還有就是這個了;原來Mysql在經過8小時不使用后會自動關閉已打開的連接,摘錄原文如下:

    5.4.

    I have a servlet/application that works fine for a day, and then stops working overnight

    MySQL closes connections after 8 hours of inactivity. You either need to use a connection pool that handles stale connections or use the "autoReconnect" parameter (see "Developing Applications with MySQL Connector/J").

    Also, you should be catching SQLExceptions in your application and dealing with them, rather than propagating them all the way until your application exits, this is just good programming practice. MySQL Connector/J will set the SQLState (see java.sql.SQLException.getSQLState() in your APIDOCS) to "08S01" when it encounters network-connectivity issues during the processing of a query. Your application code should then attempt to re-connect to MySQL at this point.

    現把具體方法貼出來,以供大家共享.
    方法一:
                   設置你的MYSQL數據庫:wait_timeout=24*60*60<秒>,把它的值設置大一點,呵呵
     方法二:
                   配置Hibernate C3p0連接池,配置如下:
    <property name="connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>
       <property name="c3p0.max_size">20</property>
       <property name="c3p0.min_size">5</property>
       <property name="c3p0.timeout">20</property>
       <property name="c3p0.max_statements">100</property>
       <property name="c3p0.idle_test_period">120</property>
       <property name="c3p0.acquire_increment">2</property>

    注意這里標紅的部分,要設置c3p0.timeout的值小于MySql的wait_timeout的值,這樣才行,要不還會出現異常.

    這次是一個教訓,所以不論從穩定還是性能的考慮,都應該選擇相對更加成熟的連接池。



    posted on 2007-05-23 10:52 java_蟈蟈 閱讀(957) 評論(0)  編輯  收藏

    只有注冊用戶登錄后才能發表評論。


    網站導航:
     
    主站蜘蛛池模板: 免费大香伊蕉在人线国产| 日韩视频在线免费| 亚洲毛片在线免费观看| 成年女人免费v片| 国产成人亚洲综合无码精品| 国产亚洲精品成人AA片| 中国好声音第二季免费播放| 97在线观免费视频观看| 中文字幕亚洲精品| 精选影视免费在线 | 免费黄色小视频网站| 亚洲宅男永久在线| 成人久久久观看免费毛片| 免费看国产精品3a黄的视频| 久久青草亚洲AV无码麻豆| 免费无遮挡无码视频在线观看| 国产91色综合久久免费| 国产亚洲无线码一区二区 | 成在线人永久免费视频播放| 亚洲A∨精品一区二区三区下载| 99久久免费精品视频| 区三区激情福利综合中文字幕在线一区亚洲视频1 | 日本免费人成网ww555在线 | 国产大片51精品免费观看| 亚洲一区二区三区播放在线| 免费一区二区无码东京热| 免费在线观看你懂的| 亚洲一区二区三区免费| 人人狠狠综合久久亚洲高清| 亚洲不卡中文字幕| 日本特黄a级高清免费大片| a免费毛片在线播放| 亚洲美女大bbbbbbbbb| 国产禁女女网站免费看| 中文字幕免费在线看电影大全| 久久久久亚洲av无码专区喷水| 日韩一品在线播放视频一品免费| 狠狠躁狠狠爱免费视频无码| 亚洲人成人77777在线播放| 日本免费网址大全在线观看| 亚洲精品日韩专区silk|