This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JDBC and the fly likes Closing a Pooled Connection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Closing a Pooled Connection" Watch "Closing a Pooled Connection" New topic
Author

Closing a Pooled Connection

Mark Butcher
Ranch Hand

Joined: Jun 28, 2012
Posts: 46
Hi friends,

Internally, what happens when we try to close a pooled connection object manually ??

Precisely, what happens to that object internally, if we get it from a connection pool and
then call connectionObject.close() method on that ??

Thanks.....
Martin Vajsar
Sheriff

Joined: Aug 22, 2010
Posts: 3606
    
  60

When you call close on the Connection instance you got from the pool, it usually means the connection gets returned to the pool and can be reused (it depends on the connection pool implementation, but I'd be surprised to find a connection pool which would do something different).

You might also obtain the physical connection (at least with some pool implementations) and close that one. However, the pool probably won't know what happened and will try to reuse the connection if you return in to the pool afterwards, in which case the next user of that connection will get an error (sometimes the pools verify connections before handing them out). However, there is no good reason to ever do something like this.
William P O'Sullivan
Ranch Hand

Joined: Mar 28, 2012
Posts: 860

Martin is correct.

A pool manager simply allocates a previously open connection (or opens one) to your app.

When you call "close()", it tags that entry as ready to be reused by another application.

Keeping the connections open is more for performance tuning by not suffering the cost of physical
opening and closing for every transaction (one of more requests).

WP
Mark Butcher
Ranch Hand

Joined: Jun 28, 2012
Posts: 46
That means closing the connection object doesn't close it, but actually returns the object back to the connection pool.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Closing a Pooled Connection
 
Similar Threads
pool objects GCed or not.
PooledConnection maximum Limit
What happens after sendredirect?
JDBC Connection Pooling Framework
what is the different between Basic DataSource and pooled DataSource