Tomcat Connection Pool Exhausted
Asked Answered
M

1

11

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?

Thanks,

Dal

This is my pool configuration:

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");
Module answered 31/3, 2015 at 11:53 Comment(0)
S
13

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.

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

Sipper answered 31/3, 2015 at 14:6 Comment(2)
Usually people forget to set following properties (use numbers accordingly) : max-idle: 8 max-active: 100 min-idle: 8Mixon
thanks! @Mixon for pointing out this max-idle, min-idle parameter settings! To be more specific, it is spring.datasource.tomcat.max-active, max-idle, min-idle. Otherwise, max-idle = max-active. see tomcat.apache.org/tomcat-8.0-doc/… and docs.spring.io/spring-boot/docs/current/reference/html/… for detailed explanation.Coed

© 2022 - 2024 — McMap. All rights reserved.