• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Connection Pooling in Servlets

 
Manal Sabri
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can anyone please explain me why connection pooling of database connections is done in servlets and exactly hw it is done .
thanks in advance ..
manal
 
Mirko Froehlich
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you do a lot of database queries, opening and closing a new connection every time is very inefficient. Therefore, you want to use connection pooling. Basically, you will need to write a Java class to represent the connection pool, possibly as a singleton. When this class is instantiated, it opens a specified number of database connections. Whenever your JSP pages or servlets need to open a connection, they request it from the connection pool class instead of creating a new one. The pool class then checks if it still has an open connection and returns it, or it blocks and waits until a connection is available again.
-Mirko
 
Ashwin Desai
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An addition to the above answer,
Connection Pool is not limited to be used for servlets. This can be used by any Database accessing servers. In fact, a similar kind of notion called as an Object Pool is also widely used to recycle the objects coz object creation time is also substantial.
Ashwin.
 
Matthew X. Brown
Ranch Hand
Posts: 165
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is some great source code for connection pooling- go to www.coreservlets.com and go to the 18th chapter-has an example and case study- I went through it and understand connection pooling much better than I did prior to it.I believe it might even implement a singleton pattern -although I don't remember exactly.
 
Matthew X. Brown
Ranch Hand
Posts: 165
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
BTW- the source code is based on a book entitled- Core Servlets and JavaServer Pages, by Marty Hall- its very good.
 
maha anna
Ranch Hand
Posts: 1467
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. I also use it. But the author overlooked to close the Statements and RedulstSet in one method. i had to fix it. Other than this the class defn is good.
regds
maha anna
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic