This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
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
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.
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
Joined: Nov 08, 2000
BTW- the source code is based on a book entitled- Core Servlets and JavaServer Pages, by Marty Hall- its very good.