• Post Reply Bookmark Topic Watch Topic
  • New Topic

How can i release DB connection object  RSS feed

 
Sudarshan Muramreddy
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,
This question was put to me recently ..

My requirement is that,i need to initially poolup some DB conecctions and need to go up till some limit depending on the request from the clients(assume i am giving/assigning these connections to ejb's).

But how can i know when to release DB connection object,or how can i know when it has done it's(DB connection object) job so that i can release it back to pool.

any idea.. how to attack this problem..


Regards,
Sudarshan
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use a pre-existing connection pool package (C3PO for example) and remember to close the connection object in a finally block after you've performed whatever DB operations you require.
[ July 01, 2004: Message edited by: Paul Sturrock ]
 
Sudarshan Muramreddy
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks paul,

But let us say if needed to build a server(or system ;-)),which will be used by users,where they can give the min. and max. connections objects number.

if user forgets to release the DB connection object..is there is any way i can keep monitoring on that object to check whether that particular DB connection object is still used,if not i can release it..

Regards,
Sudarshan
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know how connection pools decide when a connection is free to use or close. Have a look at C3P0 though - its open source so you could read the code and find out (something I might actually do, now I think about it).

Remember its not users who forget to close connections, its developers. Far easier than writing something to try to spot when it happens is to make sure your developers know that they must free up JDBC resources.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I suspect that connection manager work by "wrapping" the java.sql.Connection object in a proxy which does reference-counting to keep track of the users for a given connection. This would still require than each user called "close" when they were through, so the count could be decremented.

The pool can close and purge any connection with a reference count of 0.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!