开发者

Too many connections to datasource

开发者 https://www.devze.com 2023-01-04 22:15 出处:网络
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 conn

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 a开发者_StackOverflows 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?


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.


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).

0

精彩评论

暂无评论...
验证码 换一张
取 消