与数据源的连接过多

发布于 2024-09-07 15:07:29 字数 1788 浏览 6 评论 0原文

我有一个使用 BoneCP 进行连接池的应用程序,当我将 war 部署到 tomcat 时,它运行得很好。但是当我创建另一个战争(几乎相同,只是不同的皮肤和数据库连接)并部署它们时,我在 tomcat 启动时收到以下错误:

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

请注意,在一段时间后不会发生这种情况,所以这不是我我通过不关闭连接而是在启动时泄漏连接。

我的 spring 配置中的 hibernate/boneCP 连接属性如下:

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

有人有任何想法吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

假情假意假温柔 2024-09-14 15:07:29

根据线程:

这是您提出要求的信号
然后 BoneCP 创建更多连接
你的 mysql 服务器配置为
接受。要么增加数量
mysql 将允许的连接(通过
mysql管理员)或告诉bonecp
创建更少的连接。

默认情况下 MySQL 允许您创建
只是一些连接所以我会
首先从那开始。

PS 对验证码测试感到抱歉 -
我收到的垃圾邮件机器人尝试次数
击中令人难以置信;我要去
把它调低一个档次。

您必须减少 bonecp.maxConnectionsPerPartition,或者修改 MySQL 服务器的配置以接受60 * 应用实例数同时连接。

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.

落墨 2024-09-14 15:07:29

您创建了 3 个分区,每个分区最多有 60 个连接,因此您在那里使用 180 个连接来访问 mysql(mysql 中的默认值远远低于该连接数)。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文