Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Connection Pool Implementation ... ?

 
Vijay S. Rathore
Ranch Hand
Posts: 449
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34410
346
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vijay,
Javaworld has a good article about connection pooling.
 
Vijay S. Rathore
Ranch Hand
Posts: 449
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 572
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 449
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ali Gohar, it is a real nice explanation.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic