Tomcat连接池已耗尽 [英] Tomcat Connection Pool Exhausted

查看:180
本文介绍了Tomcat连接池已耗尽的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在项目中使用Apache Tomcat JDBC连接池.我很困惑,因为在重负载下,我一直看到以下错误:

I'm using Apache Tomcat JDBC connection pooling in my project. I'm confused because under heavy load I keep seeing the following error:

12:26:36,410 ERROR [] (http-/XX.XXX.XXX.X:XXXXX-X) org.apache.tomcat.jdbc.pool.PoolExhaustedException: [http-/XX.XXX.XXX.X:XXXXX-X] Timeout: Pool empty. Unable to fetch a connection in 10 seconds, none available[size:4; busy:4; idle:0; lastwait:10000].
12:26:36,411 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/APP].[AppConf]] (http-/XX.XXX.XXX.X:XXXXX-X) JBWEB000236: Servlet.service() for servlet AppConf threw exception: org.jboss.resteasy.spi.UnhandledException: java.lang.NullPointerException

我的期望是,通过池化,对新连接的请求将被保留在队列中,直到连接可用为止.相反,当池达到容量时,似乎拒绝了请求.这种行为可以改变吗?

My expectation was that with pooling, requests for new connections would be held in a queue until a connection became available. Instead it seems that requests are rejected when the pool has reached capacity. Can this behaviour be changed?

谢谢

Dal

这是我的池配置:

PoolProperties p = new PoolProperties();
p.setUrl("jdbc:oracle:thin:@" + server + ":" + port + ":" + SID_SVC);
p.setDriverClassName("oracle.jdbc.driver.OracleDriver");
p.setUsername(username);
p.setPassword(password);
p.setMaxActive(4);
p.setInitialSize(1);
p.setMaxWait(10000);
p.setRemoveAbandonedTimeout(300);
p.setMinEvictableIdleTimeMillis(150000);
p.setTestOnBorrow(true);
p.setValidationQuery("SELECT 1 from dual");
p.setMinIdle(1);
p.setMaxIdle(2);
p.setRemoveAbandoned(true);
p.setJdbcInterceptors(
    "org.apache.tomcat.jdbc.pool.interceptor.ConnectionState;"
    + "org.apache.tomcat.jdbc.pool.interceptor.StatementFinalizer;" 
    + "org.apache.tomcat.jdbc.pool.interceptor.ResetAbandonedTimer");

推荐答案

如果您看到日志Timeout: Pool empty. Unable to fetch a connection in 10 seconds并且您的配置为p.setMaxWait(10000);,则此设计按设计/实现方式进行.请求的线程在放弃等待连接之前等待10秒(10000毫秒,maxwait).

This working as per design/implementation, if you see the log Timeout: Pool empty. Unable to fetch a connection in 10 seconds and your configuration is p.setMaxWait(10000);. The requesting thread waits for 10seconds(10000 millseconds, maxwait) before giving up waiting for connection.

现在有两种解决方案,增加maxActive连接的数量或检查是否存在任何连接泄漏/长时间运行的查询(这是您所不希望的).

Now you have two solutions, increase the number of maxActive connection or check if there are any connection leaks/long running queries(which you do not expect).

这篇关于Tomcat连接池已耗尽的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆