与数据源的连接过多
我有一个使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据此线程:
您必须减少
bonecp.maxConnectionsPerPartition
,或者修改 MySQL 服务器的配置以接受60 * 应用实例数
同时连接。According to this thread:
You either have to decrease
bonecp.maxConnectionsPerPartition
, or modify the configuration of your MySQL server to accept60 * number of instances of your app
simultaneous connections.您创建了 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).