简体   繁体   中英

Configuring c3p0 property initialPoolSize and maxStatements using Hibernate

I am using Hibernate and I have configured some c3p0 properties in its config as specified in one of the hibernate documentation . Sample configuration looks like :

<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>

I came to know that c3p0 has many other properties that can be set via configuration file c3p0.properties but cannot be set via hibernate configuration like initialPoolSize, maxStatementsPerConnection, acquireRetryAttempts, etc in c3p0 Documentation .

My question is how can I verify if the properties I am setting in c3p0.properties are actually being used? One solution can be to enable log to debug level. Is there any other solution to confirm this? like may be via some class programmatically.

You don't need to set them in a C3P0 configuration file. You can pass any C3P0 configuration to Hibernate's config, since Hibernate passes all settings starting with the hibernate.c3p0 prefix to C3P0.

So, you can get rid of c3p0.properties and simply add new settings:

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

To see C3P0 configurations you can use a 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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM