每次呼叫随机增加C3p0连接池大小

时间:2015-01-27 09:36:45

标签: java hibernate c3p0

我正在研究中间件技术Hibernate,为了提高连接效率,我使用了 c3po ,我配置了以下参数,但在每次调用时,服务连接池大小随机增加,无需控制和每次增加连接而不使用先前打开并保持空闲的连接我已经提供配置参数,请告诉我我想要配置的内容

<property name="connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>
        <property name="hibernate.c3p0.min_size">10</property>
        <property name="hibernate.c3p0.max_size">100</property>
        <property name="hibernate.c3p0.max_statements">50</property>
        <property name="hibernate.c3p0.maxIdleTime">3600</property>
        <property name="hibernate.c3p0.maxIdleTimeExcessConnections">300</property>
        <property name="hibernate.c3p0.acquire_increment">4</property>
        <property name="hibernate.c3p0.idle_test_period">30</property>
        <property name="hibernate.c3p0.validate">true</property>
        <property name="hibernate.c3p0.preferredTestQuery">SELECT 1</property>
        <property name="hibernate.c3p0.testConnectionOnCheckin">true</property> 
        <property name="hibernate.c3p0.testConnectionOnCheckout">false</property>'

1 个答案:

答案 0 :(得分:3)

使用连接池的一个常见错误是在完成连接后忘记close连接。通常,连接池系统(如C3PO)将实际连接包装在代理中,并重定向close方法以执行向池的释放。

如果没有代码的更多细节,很难说出你的问题是什么,但这肯定是一个常见的错误 - 我第一次使用连接池时也是这样做的。

简而言之 - 请记住close关联完成后的Connection connection; try { connection = getConnection(); ... } finally { if ( connection != null ) { connection.close(); } }

您应该使用的模式应该是:

{{1}}