Java Tutorial - Java Script : Adding Connection Pooling to Tomcat

Java Tutorial - Java Script :

Adding Connection Pooling to Tomcat

The current version of Tomcat (4.1.24) has separated the connection-pooling functions from the primary distribution. Tomcat does claim to provide a Data- Source implementation without connection pooling; however, this implementation does not seem to be supported by the Tomcat Administration facility. We need connection pooling to properly access databases from servlets and make our applications scalable. Although it would be nice if we were able to use the Admin tool to install and configure DataSources, we can’t. Hopefully, Tomcat will fix this in future releases and include the connection-pooling facility as a standard part of the distribution, but in the meantime you’ll have to add connection pooling to Tomcat yourself. This section tells you how to do just that.

We will be using the Database Connection Pool implementation from the Jakarta Commons project, referred to as the DBCP. This is the standard connection pool implementation that is supported by Tomcat. The first step is to download three subprojects from Jakarta Commons. Commons can be found at Commons is a project within Jakarta designed to be a collection point for those utilities and features that are used and shared across multiple projects. The projects we need are:

·         Jakarta Commons DBCP
·         Jakarta Commons Collections
·         Jakarta Commons Pool

DBCP provides the actual connection-pooling library that we will use but it is dependent on the other two .jar files. Download the binary distributions for each of these projects and decompress the files into a working directory. (It’s a good idea to use a common jakarta directory for all Jakarta projects that you download.) After the files have been unpacked, we need to install the .jar files for Tomcat to use. The best way to do this is to copy the files into the CATALINA_HOME/common/lib subdirectory. On Linux, you need to remember to set the ownership and permissions to match those of the rest of the Tomcat installation. Following is an example of doing this on our system:

/usr/jakarta/tomcat4.1/common/lib/#chown apache:apache commons-*.jar
/usr/jakarta/tomcat4.1/common/lib/#chmod 644 commons-*.jar

After this is done, Tomcat needs to be stopped and restarted.