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

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

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

    Energy of Love  
    日歷
    <2009年8月>
    2627282930311
    2345678
    9101112131415
    16171819202122
    23242526272829
    303112345
    統計
    • 隨筆 - 70
    • 文章 - 0
    • 評論 - 80
    • 引用 - 0

    導航

    常用鏈接

    留言簿

    隨筆分類

    隨筆檔案

    搜索

    •  

    最新評論

    閱讀排行榜

    評論排行榜

     

    最近的一個項目在Hibernate使用C3P0的連接池,數據庫為Mysql。開發測試沒有問題,在運行中每個一段長的空閑時間就出現異常:


    1. org.hibernate.exception.JDBCConnectionException: could not execute query
    2. at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:74)
    3. at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
    4. .......
    5. Caused by: com.mysql.jdbc.exceptions.MySQLNonTransientConnectionException: No operations allowed after connection closed.Connection was implicitly closed due to underlying exception/error:
    6. ** BEGIN NESTED EXCEPTION **
    7. com.mysql.jdbc.CommunicationsException
    8. MESSAGE: Communications link failure due to underlying exception:
    9. ** BEGIN NESTED EXCEPTION **
    10. java.net.SocketException
    11. MESSAGE: Broken pipe
    12. STACKTRACE:
    13. java.net.SocketException: Broken pipe
    14. at java.net.SocketOutputStream.socketWrite0(Native Method)
    15. ......
    16. ** END NESTED EXCEPTION **

    查看了Mysql的文檔,以及Connector/J的文檔以及在線說明發現,出現這種異常的原因是:

    Mysql服務器默認的“wait_timeout”是8小時,也就是說一個connection空閑超過8個小時,Mysql將自動斷開該connection。這就是問題的所在,在C3P0 pools中的connections如果空閑超過8小時,Mysql將其斷開,而C3P0并不知道該connection已經失效,如果這時有Client請求connection,C3P0將該失效的Connection提供給Client,將會造成上面的異常。

    解決的方法有3種:

    1. 增加wait_timeout的時間。
    2. 減少Connection pools中connection的lifetime。
    3. 測試Connection pools中connection的有效性。

    當然最好的辦法是同時綜合使用上述3種方法,下面就DBCP和C3P0分別做一說明,假設wait_timeout為默認的8小時

    DBCP增加以下配置信息:

  • //set to 'SELECT 1'
  • validationQuery = "SELECT 1"
  • //set to 'true'
  • testWhileIdle = "true"
  • //some positive integer
  • timeBetweenEvictionRunsMillis = 3600000
  • //set to something smaller than 'wait_timeout'
  • minEvictableIdleTimeMillis = 18000000
  • //if you don't mind a hit for every getConnection(), set to "true"
  • testOnBorrow = "true"




    C3P0增加以下配置信息:
     

  • //獲取connnection時測試是否有效
  • testConnectionOnCheckin = true
  • //自動測試的table名稱
  • automaticTestTable=C3P0TestTable
  • //set to something much less than wait_timeout, prevents connections from going stale
  • idleConnectionTestPeriod = 18000
  • //set to something slightly less than wait_timeout, preventing 'stale' connections from being handed out
  • maxIdleTime = 25000
  • //if you can take the performance 'hit', set to "true"
  • testConnectionOnCheckout = true
  •  

     

     

    在配置文件中要寫成  <property name="minPoolSize"><value>1</value></property> 格式

    不能寫成 這樣<property name="properties">
       <props>
        <prop key="c3p0.initialPoolSize">1</prop>

       </props>

    </property>

    c3p0不能完全識別!!

    posted on 2009-08-11 17:27 不高興 閱讀(368) 評論(0)  編輯  收藏 所屬分類: JavaSpring
     
    Copyright © 不高興 Powered by: 博客園 模板提供:滬江博客
    主站蜘蛛池模板: 国产亚洲精品一品区99热| 中文字幕乱码系列免费| 亚洲精品线在线观看| 日韩免费视频观看| 亚洲视频免费在线看| 免费播放在线日本感人片| 日本一区二区三区在线视频观看免费| 亚洲人成7777影视在线观看| 亚洲va中文字幕无码久久| 亚洲高清免费视频| 免费毛片在线视频| 无限动漫网在线观看免费| 亚洲精品视频免费在线观看| 免费毛片a线观看| 97无码人妻福利免费公开在线视频 | 91精品国产亚洲爽啪在线影院| 亚洲日韩aⅴ在线视频| 亚洲av无码专区在线观看素人| 日韩一区二区免费视频| 无码中文字幕av免费放| 色播在线永久免费视频网站| sss在线观看免费高清| 男女猛烈无遮掩视频免费软件| 久久亚洲色WWW成人欧美| 亚洲а∨精品天堂在线| 亚洲国产精品自在自线观看| 国产精品亚洲综合五月天| 亚洲日本国产综合高清| 亚洲AV综合色区无码二区爱AV| 亚洲伊人色一综合网| 亚洲入口无毒网址你懂的| 亚洲AV无码一区二区三区牛牛| 亚洲视频无码高清在线| 亚洲最大的成人网| 亚洲成av人在线观看网站 | 国产精品免费一级在线观看| 国产自产拍精品视频免费看| 国产乱子伦片免费观看中字| 免费国产成人午夜电影| 国产福利电影一区二区三区,亚洲国模精品一区 | 国产啪精品视频网站免费尤物|