views:

338

answers:

2

I have an application that I use BoneCP for connection pooling and when I deploy the war to tomcat, it works perfectly. But when I create another war (almost identical, just different skin and DB connection) ans deploy them both the I get the following error when tomcat starts up:

com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Data source rejected establishment of connection,  message from server: "Too many connections"

Note that this does not happen after a period of time, so it is not that I am leaking connections by not closing them, but rather on startup.

My hibernate/boneCP connection properties in my spring config are as follows:

<bean id="sessionFactory"
      class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.connection.provider_class">com.jolbox.bonecp.provider.BoneCPConnectionProvider</prop>
            <prop key="hibernate.connection.driver_class">com.mysql.jdbc.Driver</prop>
            <prop key="hibernate.connection.url">${connection.url}</prop>
            <prop key="hibernate.connection.username">${connection.username}</prop>
            <prop key="hibernate.connection.password">${connection.password}</prop>
            <prop key="bonecp.idleMaxAge">60</prop>
            <prop key="bonecp.idleConnectionTestPeriod">5</prop>
            <prop key="bonecp.partitionCount">3</prop>
            <prop key="bonecp.acquireIncrement">10</prop>
            <prop key="bonecp.maxConnectionsPerPartition">60</prop>
            <prop key="bonecp.minConnectionsPerPartition">20</prop>
            <prop key="bonecp.statementsCacheSize">50</prop>
            <prop key="bonecp.releaseHelperThreads">3</prop>
        </props>
    </property>
....

Anyone got any ideas?

+2  A: 

According to this thread:

This is a sign that you have asked BoneCP to create more connections then your mysql server is configured to accept. Either increase the number of connections mysql will allow (via mysql administrator) or tell bonecp to create fewer connections.

By default MySQL allows you to create just a few connections so I would start with that first.

P.S. Sorry about the captcha test - the amount of spambot attempts I get hit with is unbelievable; I'm going to turn it down a notch.

You either have to decrease bonecp.maxConnectionsPerPartition, or modify the configuration of your MySQL server to accept 60 * number of instances of your app simultaneous connections.

Bytecode Ninja
+1  A: 

You created 3 partitions with a maximum of 60 connections each so you're hitting mysql with 180 connections there (the default in mysql is far lower than that).