aspose file tools
The moose likes JDBC and the fly likes Database Connection Pool Not Releasing Connection to pool Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Reply Bookmark "Database Connection Pool Not Releasing Connection to pool" Watch "Database Connection Pool Not Releasing Connection to pool" New topic
Author

Database Connection Pool Not Releasing Connection to pool

Joe Urbanek
Greenhorn

Joined: Jan 31, 2005
Posts: 15
I have a Class which performs JDBC calls on a DB2 Database

The Database connections are pooled via the datasource,
There is a method called getdbconnection() which obtains a pooled connection.

The issue is that the method to obtain a connection and the method to release a connection are synchronized methods on the same object (DBConnectionPool). Therefore, at any given time, only one of those methods can be called.

When the data source connection pool runs out of connections calls to DBConnectionPool.getPooledConnection() block waiting for a connection to be returned. Calls to DBConnectionPool.releasePooledConnections() then have to wait for the calls to DBConnectionPool.getPooledConnection to unblock.

Because the calls to return a connection are waiting for the calls to get a connection no connections will ever be returned and therefore no connections will ever be given causing the dead lock.

Your assistance is appreciated.

Here is example of the code:

Tim LeMaster
Ranch Hand

Joined: Aug 31, 2006
Posts: 226
You need to look into wait() and notifyAll(). You should use wait() in the getting the connection if no connections are available. This will release the lock and block until another thread with the lock calls notifyAll().

Your synchronized method gets a lock on the instance of the DBConnectionPool that the thread is using to invoke the method. However inside of the method you are accessing a static array of DBConnectionPools - so the code could be trying to allocate a connection from a pool you do not have a lock on. Of course this doesn't seem to be the whole class so things could be different in the real code. Which is a reason to post the entire class.
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

It looks like you're implementing your own ConnectionPool and you're obtaining Connections from a DataSource, where alternately you could register a Connection Pool like DBCP as your DataSource and other problems get managed by mature code.

I'm annoyed by Connection Pools. We have one written in house and it has never worked properly. My local dev environment is running DBCP with the old pool front end acting a facade to the DBCP DataSource. I look forward to kicking the old one out entirely.
Joe Urbanek
Greenhorn

Joined: Jan 31, 2005
Posts: 15
Thank you for your help your answers confirmed what I was thinking, I just needed a few more opinions, I will look into wait() and notifyAll() methods and into DBCP.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Database Connection Pool Not Releasing Connection to pool
 
Similar Threads
a mistake for bean
why jsp cannot use this class, which is no problem when compile singlely.
pool name in DBConnectionManager
does gc still have a chance to do its job if i kill the java process
Lost properties