wood burning stoves 2.0*
The moose likes JDBC and the fly likes Connection Pool Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Connection Pool" Watch "Connection Pool" New topic
Author

Connection Pool

Pendurthi prashanth
Greenhorn

Joined: Sep 13, 2005
Posts: 15
Hi...

Me and my colleague got into an argument lately. I'm relatively new to using connection pool. She says that in a connection pool connection objects are created on each request. Is that true?

If true, when is it destoryed? Would'nt it be a burden on the server?

Can any give me a link or explain how exactly a connection pool works..!

Thanks in advance

P-R-E-S-I
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336


She says that in a connection pool connection objects are created on each request. Is that true?

Well, it depends on which connection pool implementation she is talking about but generally no. Connections in the connection pool will generally be reused, rather than destroyed and recreated. When you write a piece of code that calls an open method on a connection while using a connection pool, the connecion pool will probably get an already open but currently free connection from the pool and use that, rather than explicitly creating a new conneciton. Simmilaraly, if you call the close method on the connection it will be freed up to the pool, rather than being explicitly closed. If you want to see how a connection pool does this, you might want to download the source of an open source connection pool implementation and have a look.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Prashant Jain
Greenhorn

Joined: Aug 19, 2004
Posts: 29
The only occassions I have seen connections being created is when the pool is initialized.

However paul says that it'd be "generally true". Paul, could you tell me when we could actually think of opening a connection everytime a hit is made to the pool.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Re-read my post. I don't say that it is generally true that connections are created for each request made to the pool, I say the opposite.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Connection Pool