zoukankan      html  css  js  c++  java
  • Hibernate连接数据库超时设置autoReconnect=true

    如果连接闲置8小时 (8小时内没有进行数据库操作), mysql就会自动断开连接, 要重启tomcat. 

        不用hibernate的话, connection url加参数: autoReconnect=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>
    <!-- 指定Hibernate的配置文件 -->
    <bean id="sessionFactory"
    class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="hibernateProperties">    
    <props>    
    <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>    
    <prop key="hibernate.show_sql">true</prop>    
    <prop key="hibernate.format_sql">true</prop>
    <prop key="hibernate.hbm2ddl.auto">update</prop>    
    <prop key="hibernate.autoReconnect">true</prop>
    <prop key="hibernate.autoReconnectForPools">true</prop>
    <prop key="hibernate.is-connection-validation-required">true</prop>
    <prop key="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</prop>
    <prop key="hibernate.c3p0.min_size">8</prop>
    <prop key="hibernate.c3p0.max_size">200</prop>
    <prop key="hibernate.c3p0.timeout">600</prop>
    <prop key="hibernate.c3p0.max_statements">0</prop>
    <prop key="hibernate.c3p0.idle_test_period">60</prop>
    <prop key="hibernate.c3p0.acquire_increment">2</prop>
    <prop key="hibernate.c3p0.validate">true</prop>
    </props>    
    </property>
    <property name="configLocation"
    value="classpath:hibernate.cfg.xml">
    </property>
  • 相关阅读:
    甲醛(Formaldehyde)
    Node Embedding
    受限玻尔兹曼机(RBM, Restricted Boltzmann machines)和深度信念网络(DBN, Deep Belief Networks)
    长尾分布,重尾分布(Heavy-tailed Distribution)
    SVD分解与数据压缩
    Batch Normailzation
    Attention Mechanism
    新装的Ubuntu在Nvidia显卡上分辨率不对
    人工神经网络(Artificial Neural Network)
    Xdebug+phpstorm配置
  • 原文地址:https://www.cnblogs.com/hwaggLee/p/5519361.html
Copyright © 2011-2022 走看看