Advertisement

05.06.2008 at 11:25AM PDT, ID: 23380442 | Points: 250
[x]
Attachment Details

Hibernate running out of connections in c3p0 connection pool

Tags: Java
Hello All,

I'm developing a web application that integrates spring 2.0, struts 1.3, and hibernate 3.0 running on centOS 5.0 with a postgresql 8.3.1 database.  I had changed from the default JDBC connection pool handler to c3p0 and have found that I exhaust my JDBC connections after 20 transactions (which is what my c3p0 max_size is set to).  I have changed this value and have confirmed that this is the configuration and value that is correlated with the behavior.  I don't think that the closed connections are being returned to the pool, or if they are, the application cannot re-open them.

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
Here is an excerpt from my hibernate.cfg.xml file pertaining to the c3p0 configuration:
        <property name="hibernate.c3p0.acquire_increment">1</property>
        <property name="hibernate.c3p0.min_size">10</property>
        <property name="hibernate.c3p0.max_size">20</property>
        <property name="hibernate.c3p0.timeout">100</property>
        <property name="hibernate.c3p0.max_statements">0</property>
        <property name="hibernate.c3p0.idle_test_period">1000</property>
 
In the servlets that I coded, each Hibernate Session is initialized as the following:
 
        Session = HibernateUtil.getSessionFactory().openSession();
        Transaction tx = session.beginTransaction();
 
                ... misc. data accessing ...
 
        tx.commit();
        session.close();
 
As an experiment, if I do anything regarding the session after the session.close(); statement, the application throws an error sayaing that the connection has already been closed.  Therefore, it seems like the connection is being closed properly but not being returned to the pool.  
 
Here is the output once all of the connections are exhausted:
 
12:17:53,259 DEBUG [DefaultListableBeanFactory:203] - Returning cached instance of singleton bean '/actions/regLogin'
12:17:53,259 DEBUG [SessionImpl:220] - opened session at timestamp: 4956560888868864
12:17:53,260 DEBUG [JDBCTransaction:54] - begin
 
When the servlet is hit, the application hangs until the browser detects a TCP timeout.
Start your free trial to view this solution
Question Stats
Zone: Programming
Question Asked By: CRSDC
Question Asked On: 05.06.2008
Participating Experts: 1
Points: 250
Views: 0
Translate:
Loading Advertisement...
05.06.2008 at 11:46AM PDT, ID: 21509821

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.06.2008 at 12:34PM PDT, ID: 21510262

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.06.2008 at 12:52PM PDT, ID: 21510424

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.06.2008 at 01:17PM PDT, ID: 21510666

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.06.2008 at 09:21PM PDT, ID: 21513145

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
20080236-EE-VQP-29 / EE_QW_2_20070628