aspose file tools*
The moose likes Servlets and the fly likes Connection Pooling in Servlets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Connection Pooling in Servlets" Watch "Connection Pooling in Servlets" New topic
Author

Connection Pooling in Servlets

Manal Sabri
Greenhorn

Joined: Nov 24, 2000
Posts: 2
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

Joined: Aug 21, 2000
Posts: 114
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

Joined: Jul 17, 2000
Posts: 124
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

Joined: Nov 08, 2000
Posts: 165
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

Joined: Nov 08, 2000
Posts: 165
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

Joined: Jan 31, 2000
Posts: 1467
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Connection Pooling in Servlets