-
1. Re: JBoss 5.1 is not releasing database connections
vaedama Nov 15, 2011 7:58 PM (in response to amathewjboss1)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.
-Sudheer
-
2. Re: JBoss 5.1 is not releasing database connections
amathewjboss1 Nov 16, 2011 3:00 PM (in response to vaedama)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.
Thanks
Anil Mathew
-
3. Re: JBoss 5.1 is not releasing database connections
vaedama Nov 16, 2011 3:20 PM (in response to amathewjboss1)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
@Override
public void run() {
try {
//do lookup // initialize to dataSourceXXX
//create SQL OBJECTS // initialize to sqlXXX
callRunInternal()
}
catch {
// any exception
//sql.connection.rollback()
}
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
sfcoy Nov 21, 2011 7:46 PM (in response to amathewjboss1)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.