4 Replies Latest reply on Nov 21, 2011 7:46 PM by Stephen Coy

    JBoss 5.1 is not releasing database connections

    Anil Mathew Newbie

      We have an application running on JBoss 5.1 (Linux) with JDK 1.6 and we are using SLSB. We are facing a issue where JBoss 5.1 is not releasing the Oracle connection which the application is holding.


      In other words, our application is trying to talk to an external resource (via webservice using HTTP) . The way we call the webservice is that app tier (JBoss) calls a master thread to do the send/receive process of the XML data. The master thread does have many worker threads which deals with opening the connection, reading the data. We do have a specific timeout value for the master thread so that it times out correctly and hence user won’t  see the hung page. Since the worker threads are doing the real job we really don’t care if any of the worker threads hangs or not. The issue we are seeing here is that if in case the worker thread hangs (when we have high load), the master thread (which is called by the JBoss) does time out correctly but JBoss is NOT releasing the database connection which is tied to that master thread.  Due to this we are running out of connections.


      We really don’t want to think of a DBCP solution as I thought Jboss 5.1 is capable of dealing with the database connection pooling much better. i.e. After a certain period of inactivity JBoss will passivate the session (write it to disk) after a further period of inactivity it will remove the session altogether (which will basically release the database connection).


      Any thoughts on this will help me.



      Anil Mathew

        • 1. Re: JBoss 5.1 is not releasing database connections
          Venkat Sudheer Reddy Aedama Newbie

          Here is the solution:


          You don't need to think about DBCP or C3P0


          For each class, keep all your code in try block


          catch your exceptions in catch block


          close all your connections in finally block.


          If I am correct, I know you have done till here.


          Now destroy your datasources that you have created in each class in the finally block.


          To destroy your datasources you can have a dependency on the C3P0 jar which has a datasource.destroy() method associated with it.


          More easily (without depending on any jars), you can say


          dataSource1 = null;

          dataSource2 = null;


          etc.. for all the dataSources in Finally block.


          I ran into the same problem and it took away 2 nights of my sleep. If you cannot solve this issue, post the code here. I may help you.


          Good luck.



          • 2. Re: JBoss 5.1 is not releasing database connections
            Anil Mathew Newbie

            Thank You Sudheer for the reply.


            Like you said, I am closing all the connections/ResultSet etc in the finally block.


            But like you mentioned, I really can't destroy the DataSource. One of the main reason i say that i don't create the DataSource in the each class for each connection. We have a "cached" (via static variable) connection factory which resolves the DataSource via the JNDI look up and from the DataSource we get the connection. So basically I depend fully on the Jboss to manage my connection pool. i.e if Jboss finds a inactive thread (session), it should remove altogether (which basically releases the Connection). I am sure this is happening, but in very high load with the scenerio which i mentioned it seems like Jboss has some hiccups. It could be some configuration in some Jboss files ..but i am not sure..


            I am trying to debug more on the JBoss side to see what Jboss is doing with my inactive thread (session) & associated connection. No luck on that yet though.



            Anil Mathew

            • 3. Re: JBoss 5.1 is not releasing database connections
              Venkat Sudheer Reddy Aedama Newbie

              Hello Anil,


              Are you doing lookup on your datasource in your code?


              I faced the same issue. I solved it in the end when tears rolled down looking at jboss:jca where I saw connections that were spooled were not being released after the thread execution even after closing all the db connections.


              Here is a sample: This should work.


              class Foo {

              //global variables

              Sql sqlXXX = null

              DataSource dataSourceXXX = null



              public void run() {

                try {

                 //do lookup // initialize to dataSourceXXX

                //create SQL OBJECTS // initialize to sqlXXX




              catch {

                // any exception




                finally {

                //commit // sql.connection.commit()

              //close all your result sets, database connections etc // sql.connection.close()

              //dataSource = null




              callRunInternal() {

              //your code





              If this does not work.. Please post your code snippets. We may help you.


              Thank you

              • 4. Re: JBoss 5.1 is not releasing database connections
                Stephen Coy Master

                Are you creating threads in session beans? This is not supported in any way. All EJBs in JEE 5 and earlier only support single threaded execution.


                If you're trying to control access to a limited resource (such as a web service with limited connections) then there's better solutions to this problem.