Prentice Hall and Sun Microsystems. Personal use only; do not redistribute.
18.8 Connection Pooling: A Case Study
509
Table 18.1  Connection pool timing results
Condition
Average Time
Fast LAN connection to database, 
1.8 seconds
10 initial connections, 50 max connections 
(
ConnectionPoolServlet
)
Fast LAN connection to database, 
2.0 seconds
recycling a single connection
(
ConnectionPoolServlet2
)
Fast LAN connection to database, no 
2.8 seconds
connection pooling
(
ConnectionPoolServlet3
)
Listing 18.20 ConnectionPoolServlet.java 
package coreservlets;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
/** A servlet that reads information from a database and
 *  presents it in an HTML table. It uses connection
 *  pooling to optimize the database retrieval. A good
 *  test case is ConnectionPool.html, which loads many
 *  copies of this servlet into different frame cells.
*/
public class ConnectionPoolServlet extends HttpServlet {
  private ConnectionPool connectionPool;
  
  public void doGet(HttpServletRequest request,
                    HttpServletResponse response)
      throws ServletException, IOException {
    String table;
    try {
      String query =
        "SELECT firstname, lastname " +
        " FROM employees WHERE salary > 70000";
      Connection connection = connectionPool.getConnection();
      DBResults results =
          DatabaseUtilities.getQueryResults(connection,
                                            query, false);
      connectionPool.free(connection);
Second edition of this book: www.coreservlets.com; Sequel: www.moreservlets.com.
Servlet and JSP training courses by book's author: courses.coreservlets.com.






footer




 

 

 

 

 Home | About Us | Network | Services | Support | FAQ | Control Panel | Order Online | Sitemap | Contact

jsp web hosting

 

Our partners: PHP: Hypertext Preprocessor Best Web Hosting Java Web Hosting Jsp Web Hosting Cheapest Web Hosting

Visionwebhosting.net Business web hosting division of Web Design Plus. All rights reserved