-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 
Author Message
 Post subject: Connection pool and unreleased connections (MySQL)
PostPosted: Wed Mar 11, 2009 1:53 pm 
Newbie

Joined: Fri Feb 06, 2009 8:57 pm
Posts: 8
Hibernate version: 3

Hi there,
I am having major problem with unreleased mysql connections, and I think it could be one or more from the following:
1) each time I reload the project in tomcat, connections pool remains in memory with all the connections sleeping.
2) connections are not released in my source code. I am pretty sure that I am closing them though. In addition I have some config settings (see applicationContext.xml below) to force close.
3) My configuration settings in applicationContext.xml are not effective and hence there are no real limitations on connection pool, idle time, etc.

Can someone please help me with a few hints on how I can debug this issue. My mysql server crashed several times during development because of the enormous number of mysql threads opened by my project.

Below are some details that may help you help me :)
I appreciate all replies!

Thanks,

applicationContext.xml
=================
Code:
...
   <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
      destroy-method="close">
      <property name="driverClassName" value="com.mysql.jdbc.Driver" />
      <property name="url" value="jdbc:mysql://10.1.1.100/projectx" />
      <property name="username" value="root" />
      <property name="password" value="asdfasdf" />
      <property name="maxActive" value="5" />
      <property name="maxIdle" value="5" />      
   </bean>
   <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
      <property name="dataSource">
         <ref bean="dataSource" />
      </property>
   </bean>
...

   <bean id="sessionFactory"
      class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
      <property name="dataSource">
         <ref local="dataSource" />
      </property>
      <property name="mappingResources">
         <list>
            <value>hibernate/member.hbm.xml</value>
            <value>hibernate/usergroup.hbm.xml</value>
            <value>hibernate/dataservice.hbm.xml</value>
         </list>
      </property>
      <property name="hibernateProperties">
         <props>
            <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
            <!-- Use the C3P0 connection pool provider -->
            <!-- This hasn't been tested. TODO: Test connection pool -->
            <prop key="hibernate.c3p0.min_size">1</prop>
            <prop key="hibernate.c3p0.max_size">10</prop>
            <prop key="hibernate.c3p0.timeout">100</prop>
            <prop key="hibernate.c3p0.max_statements">0</prop>
            <prop key="hibernate.c3p0.idle_test_period">30</prop>   
            <prop key="hibernate.connection.release_mode">after_statement</prop>
            <prop key="hibernate.connection.aggressive_release">true</prop>            
         </props>
         
      </property>
   </bean>
   <bean id="transactionManager"
      class="org.springframework.orm.hibernate3.HibernateTransactionManager">
      <property name="sessionFactory">
         <ref local="sessionFactory" />
      </property>
   </bean>
...




MySQL growing processlist:
===================

| NULL |
| 82 | root | irene.mydomain.local:4107 | db | Sleep | 1214 |
| NULL |
| 402 | root | apple.mydomain.local:3176 | NULL | Query | 0 |
NULL | SHOW PROCESSLIST |
| 551 | root | apple.mydomain.local:3302 | projectx | Sleep | 1303 |
| NULL |
| 553 | root | apple.mydomain.local:3305 | projectx | Sleep | 1302 |
| NULL |
| 555 | root | apple.mydomain.local:3310 | projectx | Sleep | 1301 |
| NULL |
| 559 | root | apple.mydomain.local:3314 | projectx | Sleep | 1297 |
| NULL |
| 561 | root | apple.mydomain.local:3316 | projectx | Sleep | 1296 |
| NULL |
| 563 | root | apple.mydomain.local:3318 | projectx | Sleep | 1296 |
| NULL |
| 567 | root | apple.mydomain.local:3322 | projectx | Sleep | 1293 |
| NULL |
| 569 | root | apple.mydomain.local:3324 | projectx | Sleep | 1292 |
| NULL |
| 571 | root | apple.mydomain.local:3326 | projectx | Sleep | 1264 |
| NULL |
| 652 | root | apple.mydomain.local:3552 | projectx | Sleep | 894 |
| NULL |
| 654 | root | apple.mydomain.local:3554 | projectx | Sleep | 894 |
| NULL |
| 656 | root | apple.mydomain.local:3556 | projectx | Sleep | 894 |
| NULL |
| 658 | root | apple.mydomain.local:3558 | projectx | Sleep | 892 |
| NULL |
| 660 | root | apple.mydomain.local:3561 | projectx | Sleep | 891 |
| NULL |
| 662 | root | apple.mydomain.local:3570 | projectx | Sleep | 890 |
| NULL |
| 664 | root | apple.mydomain.local:3573 | projectx | Sleep | 890 |
| NULL |
+-----+------+----------------------------------+-------------+---------+------+
-------+------------------+
23 rows in set (0.00 sec)

mysql>


Top
 Profile  
 
 Post subject: Re: Connection pool and unreleased connections (MySQL)
PostPosted: Thu Jul 23, 2009 7:53 am 
Newbie

Joined: Tue Jun 30, 2009 11:03 am
Posts: 7
Hi,

Did you solve your problem? I'm having the same, I'm trying to figure it out since 2 days now and it's kinda driving me crazy.

Thank you


Top
 Profile  
 
 Post subject: Re: Connection pool and unreleased connections (MySQL)
PostPosted: Mon Aug 10, 2009 7:12 am 
Newbie

Joined: Mon Aug 10, 2009 7:00 am
Posts: 2
I am also facing the same issue, please let me know if you have found the solution for it

Thanks
Vishal


Top
 Profile  
 
 Post subject: Re: Connection pool and unreleased connections (MySQL)
PostPosted: Mon Aug 31, 2009 7:13 pm 
Newbie

Joined: Mon Aug 31, 2009 6:11 pm
Posts: 2
I am a newbee, so take this for what it may be worth. I had the same problem and found some discussion on setting the MySQL server startup timeout variables to shorter intervals. Evidently, this allows MySQL to recover the sleeping threads. As a test, I set the wait timeout to 60 seconds, and the sleeping threads were recovered accordingly. I have not tested the other timeout settings and have no idea how changes might affect your application. This seems to work with a proof of concept application in an article by Maik Schumacher titled "Flex, BlazeDS, and Hibernate JPA on Tomcat and MySQL – Part 2: Extending the demo to use linked database relations" http://www.adobe.com/devnet/flex/articl ... e_pt2.html

Hope this helps.


Top
 Profile  
 
 Post subject: Re: Connection pool and unreleased connections (MySQL)
PostPosted: Tue Sep 01, 2009 4:21 am 
Newbie

Joined: Fri Aug 14, 2009 7:32 am
Posts: 5
Hi,

Are you using the MySQL JDBC driver within the web application(In WEB-INF/lib) or out side?

Regards,
Robert.


Top
 Profile  
 
 Post subject: Re: Connection pool and unreleased connections (MySQL)
PostPosted: Tue Sep 01, 2009 9:02 am 
Newbie

Joined: Mon Aug 31, 2009 6:11 pm
Posts: 2
I believe it is within the project. The code contains mysql-connector-java-5.1.7-bin.jar in the WEB-INF/lib folder.


Top
 Profile  
 
 Post subject: Re: Connection pool and unreleased connections (MySQL)
PostPosted: Fri Sep 04, 2009 5:31 am 
Newbie

Joined: Fri Aug 14, 2009 7:32 am
Posts: 5
Hi,

According to your configurations, it seem you're using both commons-dbcp and c300 for connection pooling. Is that intentional?

Here goes DBCP.
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://10.1.1.100/projectx" />
<property name="username" value="root" />
<property name="password" value="asdfasdf" />
<property name="maxActive" value="5" />
<property name="maxIdle" value="5" />
</bean>

and here c3p0 :

<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<!-- Use the C3P0 connection pool provider -->
<!-- This hasn't been tested. TODO: Test connection pool -->
<prop key="hibernate.c3p0.min_size">1</prop>
<prop key="hibernate.c3p0.max_size">10</prop>
<prop key="hibernate.c3p0.timeout">100</prop>
<prop key="hibernate.c3p0.max_statements">0</prop>
<prop key="hibernate.c3p0.idle_test_period">30</prop>
<prop key="hibernate.connection.release_mode">after_statement</prop>
<prop key="hibernate.connection.aggressive_release">true</prop>
</props>

</property>

Instead of using both try either with DBCP of C3P0. If you are going to use DBCP you can set dataSource bean properties like this.

</property>
<property name="initialSize">
<value>5</value>
</property>
<property name="maxActive">
<value>8</value>
</property>
<property name="maxIdle">
<value>4</value>
</property>


Regards,
Robert.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.