san
san

Reputation: 3

Tomcat connection pool not releasing idle connections

I am using tomcat DBCP on tomcat 7.0.42 with Oracle database. Following is an example of my resource definition:

<Resource name="jdbc/DB_alias1"
   auth="Container"
   type="javax.sql.DataSource"
   fairQueue="true"
   username="user"
   password="password"
   driverClassName="oracle.jdbc.OracleDriver"
   url="jdbc:oracle:thin:@(...)"
   timeBetweenEvictionRunsMillis="180000"
   minEvictableIdleTimeMillis="120000"
   maxActive="50"
   maxIdle="4"
   minIdle="4"
   maxWait="10000"
   initialSize="4"
   initSQL="<A valid init SQL>"
   validationQuery="SELECT 1 from dual"
   validationInterval="60000"
   testOnBorrow="false"
   testOnReturn="false"
   testWhileIdle="true"
   removeAbandonedTimeout="120"
   removeAbandoned="true"
   logAbandoned="false"
/>

On startup 4 initial connections are created. Based on the above configuration, after minEvictableIdleTimeMillis, all idle connections should be eligible for being recycled/destroyed.

Since I have 4 minIdle connections, I expect these 4 connections to recycled/destroyed every timeBetweenEvictionRunsMillis seconds and 4 new connections to be created with a fresh logon time. On checking connections in database, I see that the logon time remains the same from when initial connections were created and these never update even after a day or two. These stale connections are providing incorrect results in case there has been any change in data from DB.

This was not the case with Apache commons DBCP where connections were recycled automatically based on the timeBetweenEvictionRunsMillis.

I tried searching this forum for hints on a solution but nothing has worked so far. I was wondering if I may not have the configurations done right. Any insight will be greatly appreciated.

Thanks!

Upvotes: 0

Views: 4228

Answers (1)

Thilo
Thilo

Reputation: 262504

Since I have 4 minIdle connections, I expect these 4 connections to recycled/destroyed every timeBetweenEvictionRunsMillis seconds

No. Quite the opposite. minIdle = 4 says that you allow four connections to remain in the pool even when they are idle (in fact, the pool will even grow to maintain four idle connections if necessary).

These stale connections are providing incorrect results in case there has been any change in data from DB.

That should never happen, no matter when the connection was created.

A connection will issue a fresh query, even if the connection was created days ago. Unless you have some very weird caching in place.

What could happen with idle connections is that they time-out and get disconnected. But that should be taken care of by the validationQuery.

Upvotes: 1

Related Questions