C3PO解决数据库重启后tomcat在不需要重启的情况下即可重新获得数据连接的问题。
按照以下配置,怎么当DB断开又重新启动后,WEB工程还是报错:
ERROR: org.hibernate.util.JDBCExceptionReporter - OALL8 处于不一致状态
只有当TOMCAT重新启动后,WEB工程才可以正常运行。
网上说C3P0可以解决数据库重启后tomcat在不需要重启的情况下即可重新获得数据连接的问题。但为什么不行呢
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="mappingLocations" value="${hibernate.mapping.locations}" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
${hibernate.dialect}
</prop>
<prop key="hibernate.show_sql">
${hibernate.show_sql}
</prop>
<prop key="hibernate.use_sql_comments">
${hibernate.use_sql_comments}
</prop>
<prop key="hibernate.connection.provider_class">
org.hibernate.connection.C3P0ConnectionProvider
</prop>
<!--连接池的最小连接数 -->
<prop key="hibernate.c3p0.min_size">
5
</prop>
<!--最大连接数 -->
<prop key="hibernate.c3p0.max_size">
50
</prop>
<!--连接超时时间 -->
<prop key="hibernate.c3p0.timeout">
120
</prop>
<!--statemnets缓存大小 -->
<prop key="hibernate.c3p0.max_statements">
100
</prop>
<!--每隔多少秒检测连接是否可正常使用 -->
<prop key="hibernate.c3p0.idle_test_period">
120
</prop>
<!--当池中的连接耗尽的时候,一次性增加的连接数量,默认为3 -->
<prop key="hibernate.c3p0.acquire_increment">
2
</prop>
<!-- 每次都验证连接是否可用 -->
<prop key="hibernate.c3p0.validate">
true
</prop>
</props>
</property>
</bean>