posted 16 years ago
If you want to have the costly database connectins to be created alreday and ready for all servlets within an web application, you can create a COMMON Connection Pool of Database connections and put it in ServletContext. Each Servlet when first loaded checks for the connection-pool attribute in ServletContext, if not found then creates one and it volunteers to put it in servletCOntext. Essentially if there are 10 servlets in the whole web application ONLY one of the 10 will CREATE the connection pool and others just USE the already exisiting Connection pool in Servlet Context. I use this tech, and I add this code in init() of each servlet.