Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tomcat Connection Pool Exhausted

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");
like image 262
Dal Avatar asked Mar 31 '15 11:03

Dal


1 Answers

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

like image 149
Karthik Prasad Avatar answered Oct 14 '22 15:10

Karthik Prasad