The moose likes JDBC and Relational Databases and the fly likes Connection Pool Implementation ... ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Connection Pool Implementation ... ?" Watch "Connection Pool Implementation ... ?" New topic

Connection Pool Implementation ... ?

Vijay S. Rathore
Ranch Hand

Joined: Oct 29, 2001
Posts: 449
What is the logic behind connection pooling? How it is implemented? I am looking for some details at the design as well as implementation level. Any tips or links will help.

SCJP, SCJD, SCWCD1.4, IBM486, IBM484, IBM 483, IBM 287, IBM141, IBM Certified Enterprise Developer - WebSphere Studio, V5.0
Author of IBM 287 Simulator Exam
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33098

Javaworld has a good article about connection pooling.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Vijay S. Rathore
Ranch Hand

Joined: Oct 29, 2001
Posts: 449
Thanks Jeanne Boyarsky, I am already aware of connection pooling and have used it in some projects, but recently in one of the interviews the interviewer asked me how to implement the connection pooling, if I have to write the customized connection pool for some application. So I was more interested in writing a customized connection pool application.
Ali Gohar
Ranch Hand

Joined: Mar 18, 2004
Posts: 572
As you know already that in Connection Pooling we have the pool of connections made. Different users use the connection and then give it back to the client. So to develope your own connection pool you will make a connection manager class as singlton and use any Collection object to store the connections.

You will define getConnection,releaseConnection methods in that class. which will give the connection from the pool and take back the connection and insert into the pool.

Major issue to consider in this regard is that you should implement your class as thread safe. If different users request for a connection at the same time and pool is empty then users should wait until a connection is released by another users.

You will define how many connections will you provide and there are different approaches in this regard. You can initialize all the required connections and store then in pool or you will initialize connection on demand.
Vijay S. Rathore
Ranch Hand

Joined: Oct 29, 2001
Posts: 449
Thanks Ali Gohar, it is a real nice explanation.
I agree. Here's the link:
subject: Connection Pool Implementation ... ?
jQuery in Action, 3rd edition