proxool连接池空闲连接中断问题解决

原文地址:http://www.proxool.com/html/proxoolerror/20080308/49.html 
mysql 八小时断开连接异常,一起说明下. 

这里以mysql 8小时断开连接说下 

mysql的my.ini(my.cnf)本身有个设置 

interactive_timeout 

wait_timeout 

是设置断开的时间设置,愚蠢的版本就是直接加大这两个值 

正确的解决办法 

<driver-url>jdbc:mysql://localhost/testdb?autoReconnect=true&amp;useUnicode=true&amp;characterEncoding=utf-8</driver-url> 

加上 autoReconnect=true 

还有使用 

<house-keeping-test-sql>select CURRENT_DATE</house-keeping-test-sql> 

配置文件看起来像这样的 

proxool.xml 

<?xml version="1.0" encoding="UTF-8"?> 
<!-- the proxool configuration can be embedded within your own application's. 
Anything outside the "proxool" tag is ignored. --> 
<something-else-entirely> 
  <proxool> 
    <alias>DBTest</alias> 
    <driver-url>jdbc:mysql://localhost/testdb?autoReconnect=true&amp;useUnicode=true&amp;characterEncoding=utf-8</driver-url> 
    <driver-class>com.mysql.jdbc.Driver</driver-class> 
    <driver-properties> 
      <property name="user" value=""/> 
      <property name="password" value=""/> 
    </driver-properties> 
    <house-keeping-sleep-time>9000</house-keeping-sleep-time> 
    <!--  <prototype-count>3</prototype-count> --> 
    <maximum-connection-count>25</maximum-connection-count> 
    <minimum-connection-count>5</minimum-connection-count> 
    <house-keeping-test-sql>select CURRENT_DATE</house-keeping-test-sql> 
  </proxool> 
</something-else-entirely> 


如果使用Hibernate+Proxool在hibernate.cfg.xml也需要加上 

<property  name="connection.autoReconnect">true</property> 

看起来像这样的 



   <property name="hibernate.connection.provider_class">org.hibernate.connection.ProxoolConnectionProvider</property>
    <property name="dialect">org.hibernate.dialect.MySQLDialect</property> 
    

    <property  name="statement_cache.size">25</property> 
    <property  name="jdbc.fetch_size">50</property> 
    <property  name="jdbc.batch_size">50</property> 

    <property  name="connection.autoReconnect">true</property> 
    <property  name="connection.autoReconnectForPools">true</property> 
    <property  name="connection.is-connection-validation-required">true</property> 

    <property name="hibernate.proxool.pool_alias">DBTest</property> 
    <property name="hibernate.proxool.xml">proxool.xml</property> 


   <mapping resource="hibernate/map/test.hbm.xml" /> 
</session-factory> 

</hibernate-configuration>

posted @ 2013-04-22 11:30  但用此心  阅读(640)  评论(0编辑  收藏  举报