我正在使用 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 设置,但不能通过 hibernate 配置设置,如 initialPoolSize、maxStatementsPerConnection、acquireRetryAttempts 等 c3p0 Documentation .
我的问题是如何验证我在 c3p0.properties 中设置的属性是否实际被使用?一种解决方案是将日志启用到调试级别。还有其他解决方案可以确认这一点吗? like 可能以编程方式通过某些类。
最佳答案
您不需要在 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 .如果您想监视连接池的使用情况并为不可预见的流量峰值提供回退机制,那么您应该看看 FlexyPool .
关于java - 使用 Hibernate 配置 c3p0 属性 initialPoolSize 和 maxStatements,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28518891/