1

I am working on a web project in which i have used c3p0 in web services.I have configured the following pararamters in hibernate.cfg.xml file.But even though i have given max_size is 10000 and idle test period is 30 ,Sometimes mysql server is not providing another connection to db.So the website is getting load and load till i restart my server.And my in log shows "too many conection are opened".What i miss in the following configuration.Please help me out

<property name="hibernate.c3p0.min_size">10</property>
        <property name="hibernate.c3p0.max_size">10000</property>
        <property name="hibernate.c3p0.max_statements">5000</property>
        <property name="hibernate.c3p0.maxIdleTime">1000</property>
        <property name="hibernate.c3p0.maxIdleTimeExcessConnections">500</property>
        <property name="hibernate.c3p0.acquire_increment">100</property>
        <property name="hibernate.c3p0.idle_test_period">30</property>
        <property name="hibernate.c3p0.validate">true</property>
        <property name="hibernate.c3p0.preferredTestQuery">SELECT 1</property>
        <property name="hibernate.c3p0.testConnectionOnCheckin">true</property>
        <property name="hibernate.c3p0.testConnectionOnCheckout">false</property>
Vicky
  • 1,412
  • 4
  • 18
  • 30

1 Answers1

0

You very likely have a Connection leak. A gigantic pool size won't really help with that. Please see here.

Appendix: Robust Resource Cleanup idiom

It's best when you can to use try with resources. But if you are working with an older version of Java (pre Java 7), or with resources that don't implement AutoCloseable you may still have to revert to this kind of thing.

Connection c     = null;
OtherResource or = null;

try
{
   c  = cpds.getConnection();
   or = getOtherResource()

   // do stuff
   // ...
}
finally
{
  try { if (or != null) or.close(); }
  catch (Exception e) { e.printStackTrace(); }

  try { if (c != null) c.close(); }
  catch (Exception e) { e.printStackTrace(); }
}

Note that the finally clause will definitely be executed if the Connection is acquired, and there is a best-attempt close() of each resource: If or fails to close(), that Exception won't prevent the attempt to close() the Connection.

You have to be very careful. As Keynes famously put it, there's many a slip 'twixt the cup and the lip.

Steve Waldman
  • 13,689
  • 1
  • 35
  • 45
  • Yeah i understand but i am closing each and every session which is opened in dao layer like sessionobj.clear(); sessionobj.flush(); sessionobj.close(); – Vicky Aug 09 '16 at 11:10
  • so you think. are you using Java 7+ try-with-resources or else the cumbersome, old-fashioned robust resource cleanup idiom? see http://stackoverflow.com/questions/11784674/spring-c3p0-postgres/11786683#11786683 if you use try parameters described at the link above, i suspect that you will see that you are not. i could be wrong! but just closing sessions after use isn't enough. exceptions happen. – Steve Waldman Aug 09 '16 at 11:17
  • My goto robust-resource-cleanup link seems to have expired, I've updated the post with an explanation (scraped from [here](https://sourceforge.net/p/c3p0/mailman/c3p0-users/?viewmonth=200811)). – Steve Waldman Aug 09 '16 at 11:33