使用 Hibernate 配置 c3p0 属性 initialPoolSize 和 maxStatements

Configuring c3p0 property initialPoolSize and maxStatements using Hibernate

我正在使用 Hibernate,并且我已经按照 hibernate documentation 之一中指定的配置在其配置中配置了一些 c3p0 属性。示例配置如下:

<property name="hibernate.c3p0.min_size">5</property>
<property name="hibernate.c3p0.max_size">20</property>
<property name="hibernate.c3p0.timeout">300</property>
<property name="hibernate.c3p0.max_statements">50</property>
<property name="hibernate.c3p0.idle_test_period">3000</property>

我了解到 c3p0 还有许多其他属性可以通过配置文件 c3p0.properties 设置,但不能通过 c3p0 Documentation 中的 initialPoolSize、maxStatementsPerConnection、acquireRetryAttempts 等休眠配置设置。

我的问题是如何验证我在 c3p0.properties 中设置的属性是否真的被使用了?一种解决方案是将日志启用到调试级别。还有其他解决方案可以确认这一点吗? like 可能是通过一些 class 以编程方式实现的。

您不需要在 C3P0 配置文件中设置它们。您可以将任何 C3P0 配置传递给 Hibernate 的配置,因为 Hibernate 将所有以 hibernate.c3p0 前缀开头的设置传递给 C3P0.

因此,您可以删除 c3p0.properties 并简单地添加新设置:

<property name="hibernate.c3p0.initialPoolSize">1</property>
<property name="hibernate.c3p0.maxStatementsPerConnection">10</property>
<property name="hibernate.c3p0.acquireRetryAttempts">5</property>

要查看 C3P0 配置,您可以使用 JMX client. If you want to monitor the connection pool usage and also provide a fall-back mechanism for unforeseen traffic spikes, then you should take a look at FlexyPool