<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)  編輯  收藏

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


    網站導航:
     
    主站蜘蛛池模板: 亚洲色大成网站www永久网站| 最近免费mv在线观看动漫 | 一级午夜a毛片免费视频| 久久国产乱子免费精品| 国产高清视频在线免费观看| 暖暖在线日本免费中文| 亚洲欧美aⅴ在线资源| 午夜免费啪视频在线观看| 午夜国产大片免费观看| 亚洲人成电影在线观看网| 亚洲精品偷拍视频免费观看| 亚洲第一成年免费网站| 亚洲国产日韩一区高清在线| 在线播放免费人成视频网站| 97在线观免费视频观看| 亚洲熟妇无码AV不卡在线播放| 国产免费AV片在线播放唯爱网| 亚洲a级片在线观看| 日韩av无码久久精品免费| 亚洲中文久久精品无码ww16| 在线91精品亚洲网站精品成人| 亚洲日本在线免费观看| 亚洲国产精品无码久久一区二区| 香蕉视频亚洲一级| 在线免费观看污网站| 亚洲中文字幕无码一去台湾| 精品无码AV无码免费专区| 亚洲一区二区三区自拍公司| 污污污视频在线免费观看| 国产亚洲精品自在线观看| 日本高清不卡中文字幕免费| 久久久久国色AV免费观看性色| 亚洲视频在线不卡| 99re6热视频精品免费观看| 色老板亚洲视频免在线观| 亚洲成AⅤ人影院在线观看| 国产AV无码专区亚洲AV麻豆丫 | 亚洲人JIZZ日本人| 免费成人福利视频| 亚洲国产午夜精品理论片| 免费国产真实迷j在线观看|