Tomcat - database connections problems

Posted on 2005-04-25
Last Modified: 2010-03-17
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.

Question by:Mweallans

    Accepted Solution

    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 -->
    LVL 1

    Assisted Solution

    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


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
    ADCs have gained traction within the last decade, largely due to increased demand for legacy load balancing appliances to handle more advanced application delivery requirements and improve application performance.
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now