hibernate 4会话连接保持打开状态

时间:2014-11-11 07:29:37

标签: hibernate c3p0

我在java应用程序中使用hibernate和mysql数据库 我从hibernate 3迁移到hibernate 4 但是在新的hibernate繁忙的线程数量增加,它使用所有的连接 所以我的应用程序停止工作,不能再提供连接。 我的hibernate.cfg配置如下:

        <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
        <!-- Enable Hibernate's automatic session context management -->
        <property name="current_session_context_class">thread</property>
        <property name="hibernate.current_session_context_class">thread</property>
        <!-- Disable the second-level cache -->
        <property name="hibernate.cache.use_second_level_cache">true</property>
        <!--<property name="hibernate.cache.provider_class">
            net.sf.ehcache.hibernate.EhCacheProvider
        </property>-->
        <property name="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory</property>
        <property name="hibernate.cache.use_query_cache">true</property>

        <!--<property name="hibernate.generate_statistics">true</property>-->

        <!--C3P0 configure-->
        <property name="hibernate.connection.provider_class">
            org.hibernate.connection.C3P0ConnectionProvider
        </property>
        <property name="hibernate.c3p0.acquire_increment">3</property>
        <property name="hibernate.c3p0.idle_test_period">144</property>
        <property name="hibernate.c3p0.timeout">60</property>
        <property name="hibernate.c3p0.max_size">30</property>
        <property name="hibernate.c3p0.min_size">3</property>
        <property name="hibernate.c3p0.max_statements">0</property>
        <property name="hibernate.c3p0.preferredTestQuery">select 1;</property>
        <property name="hibernate.c3p0.validate">true</property>
        <property name="hibernate.c3p0.testConnectionOnCheckout">true</property>

我将超时设置为较小值并增加max_size 并设置use_second_level_cache = false 但没有改进

问题是什么

非常感谢

1 个答案:

答案 0 :(得分:0)

所以这听起来非常类似于应用程序中的连接泄漏。使用c3p0 config params unreturnedConnectionTimeoutdebugUnreturnedConnectionStackTraces进行调试。

请参阅here

(在你的hibernate.cfg中,他们是hibernate.c3p0.unreturnedConnectionTimeouthibernate.c3p0.debugUnreturnedConnectionStackTraces。)

相关问题