• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 179
  • Last Modified:

Tomcat - database connections problems

I am a database professional and I have recently been charged with discovering why we can't run database admin activities in the middle of the night.  Basically we need exclusive access and we can't seem to get it because there are tomcat connections still active.  These often include conections that have been active for more than 12 hours but from the database admin tools I have been able to determine that these connections haven't communicated with the database for as much as 12 hours.

I have just done some more investigations and have discovered that these connections eventually get cleared the next morning and the time they are cleared seems to vary according to the app server they are coming from.  I am sure this is a tomcat problem, but that is where I need help.  Is there any way in which I can ensure that connections are cleared when they have been idle for about 1 hour?  Is there any way that I can run a command to clear all tomcat connections.

I have tried shutting down the database server and bringing it up again, and then running the database admin activities but when I do this the users complain that they can't run certain tomcat driven activities the next day until tomcat is restarted.

Any help would be much appreciated.

2 Solutions
If Tomcat is using database connection pooling via the Jakarta Commons DBCP, then you can have the server automatically clear abandoned connections.  Add the following parameters to your <ResourceParams> directive (possibly in server.xml) for the datasources that are causing the problems:

              <value>60</value> <!-- value in seconds -->
As jbanafato says, you need to set the inactivitity time-out for the database connection pool.
You say you're using Tomcat, so the most probable connection pool your application is using is the Jakarta Commons DBCP. But there are others aswell. I think you should speak the developer of the application and consult him about this. Should be a quick fix for him/her.

Common database connection pools in java (all of these have inactivity timeouts which can be set for the connections in the pool):

Db Connection Broker



Jakarta DBCP


Featured Post

Granular recovery for Microsoft Exchange

With Veeam Explorer for Microsoft Exchange you can choose the Exchange Servers and restore points you’re interested in, and Veeam Explorer will present the contents of those mailbox stores for browsing, searching and exporting.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now