Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The use of c3p0.idle_test_period.

I'm new to c3op, and confused about the use of :

c3p0.idle_test_period

In this link : HowTo configure the C3P0 connection pool

idleTestPeriod :  Must be set in hibernate.cfg.xml (or hibernate.properties), Hibernate default:  
0, If this is a number greater than 0, c3p0 will test all idle, pooled but unchecked-out  
connections, every this number of seconds.

What is the purpose of this kind of test (idel, pooled connections), and the relationship between c3p0.idle_test_period and c3p0.timeout?

like image 455
TU_HEO DAKAI Avatar asked Apr 16 '12 14:04

TU_HEO DAKAI


People also ask

What is c3p0 used for?

c3p0 is a Java library that provides a convenient way for managing database connections. In short, it achieves this by creating a pool of connections. It also effectively handles the cleanup of Statements and ResultSets after use.

How does c3p0 connection pool work?

c3p0 is an easy-to-use library for making traditional JDBC drivers “enterprise-ready” by augmenting them with functionality defined by the jdbc3 spec and the optional extensions to jdbc2. As of version 0.9. 5, c3p0 fully supports the jdbc4 spec.

What is hibernate c3p0 Idle_test_period?

cfg. xml (or hibernate. properties), Hibernate default: 0, If this is a number greater than 0, c3p0 will test all idle, pooled but unchecked-out connections, every this number of seconds. What is the purpose of this kind of test (idel, pooled connections), and the relationship between c3p0.

What is c3p0 in hibernate?

C3p0 is an open-source JDBC connection pooling library, with support for caching and reuse of PreparedStatements. Hibernate provides support for Java applications to use c3p0 for connection pooling with additional configuration settings.


2 Answers

The database server may close a connection on its side after a certain amount of time - causing some error in your application, because it'll attempt to send a query on a connection which is no longer available on the server side.

In order to avoid this you can let the pool periodically check a connection (Think of a ping) for it's validity. This is what idle_test_period is for.

timeout is the timespan after which the pool will remove a connection from the pool, because the connection wasn't checked out (used) for a while and the pool contains more connections than c3pO.min_size.

like image 89
MartinK Avatar answered Sep 23 '22 06:09

MartinK


I think this setting is used in hibernate in order to validate pooled connection after every few seconds . Consider a scenario if on database side, password is changed. Hibernate already pooled connections on old password. So it is security breach having pool with wrong password.So when hibernate will validate after few seconds it . It will invalidate that pooled connection.

like image 26
anand kadu Avatar answered Sep 21 '22 06:09

anand kadu