Java Reference
In-Depth Information
The database you use will, of course, determine the number of connections you can
really have opened at once. Consult your database documentation or license agree-
ment for this number.
Inter-Servlet Communications
In the previous section, you saw how a connection pool saves you a lot of time when servicing
requests. Wouldn't it be nice if, instead of creating a ConnectionPool local only to one spe-
cific servlet, you could have a ConnectionPool that was global to all your servlets? To do this,
you will need to create a servlet that can manage a ConnectionPool object and provide a way
for other servlets to communicate with it. Listing 7.10 contains the source for a servlet that
will do just this.
package ConnectionPool;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
public class ConnectionPoolServlet extends HttpServlet {
//Initialize global variables
public void init(ServletConfig config)
throws ServletException {
// Instantiate the ConnectionPool
ConnectionPool pool = new ConnectionPool();
try {
// Set the JDBC Driver
// Set the URL to the Datasource
pool.setURL(“jdbc:odbc:Movie Catalog”);
// Set the initial size of the Connection Pool
Search WWH ::

Custom Search