简体   繁体   English

如何缩小数据库连接池?

[英]How to shrink DB Connection Pool?

I am using Apache DBCP with JNDI in my tomcat container to pool connections to a mysql database. 我在tomcat容器中使用带有JNDI的Apache DBCP来池化到mysql数据库的连接。 Everything works fine but a problem i am seeing is that once a pconnection is pooled it is never released. 一切正常,但是我看到的一个问题是,一旦将pconnection池化,就永远不会释放它。 So after a load spike connection sit their forever sleeping. 因此,在负载峰值连接之后,他们将永远处于睡眠状态。 Is their a way to shrink the pool through context.xml parameters? 他们是否可以通过context.xml参数缩小池? here is my ocnfiguration: 这是我的名字:

        defaultAutoCommit="false"
        defaultTransactionIsolation="REPEATABLE_READ"
        auth="Container"
        type="javax.sql.DataSource"
        logAbandoned="true" 
        removeAbandoned="true"
        removeAbandonedTimeout="300" 
        maxActive="-1"
        initialSize="15"
        maxIdle="10"
        maxWait="10000" 
        username="user"
        password="password"
        driverClassName="com.mysql.jdbc.Driver"
        url="jdbc:mysql://localhost/mydb"/>

尝试将minEvictableIdleTimeMillis设置为低于其默认值1000*60*30

尝试使用c3p0连接池`~~

In comparable situations I've used Tomcat's JMX adapter to tweak the settings of the connection pool. 在类似的情况下,我使用了Tomcat的JMX适配器来调整连接池的设置。 This can be used both, to increase and to decrease thesize of the pool. 可以同时使用它来增加和减小池的大小。 It is therefore a good idea to enable JMX remote access to the servlet container at least in production environments, just to have some chance to react on exceptional operational situations. 因此,至少在生产环境中启用JMX远程访问servlet容器是一个好主意,以便有机会对特殊的操作情况做出反应。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM