aspose file tools
The moose likes Servlets and the fly likes Where To Place Connection Pool Classes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Groovy Fundamentals video training course this week in the Groovy forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Where To Place Connection Pool Classes" Watch "Where To Place Connection Pool Classes" New topic

Where To Place Connection Pool Classes

Vikas Aggarwal
Ranch Hand

Joined: Jun 22, 2001
Posts: 140
I am using Connection Pooling and tomcat. The connection pool package contains 2 class files. I have placed the package in the webapps/<myproject-name>/WEB-INF/classes directory. It works fine but a little slow. On the net I came across these following statements. Please help me understand it and let me if I am doing the right thing.
Most Servlet Engines use a special class loader for Servlets to be able to automatically reload a Servlet when it is modified. This class loader handles all class files located in a special directory, typically named servlets. A common mistake among new Servlet developers is to also put helper classes, such as the connection pool classes , in the servlets directory. This doesn't work at all when static variables are involved since the special class loader creates a separate class instance for each Servlet. To avoid this problem you should place all helper classes in the regular CLASSPATH used by the Servlet Engine. How you set the CLASSPATH varies between Servlet Engines so read the documentation for the product you use.

Vikas Aggarwal

Founder @
Leads and Deals Limited
Prashanth menon
Ranch Hand

Joined: Feb 20, 2001
Posts: 65
hi Vikinsa,
The logic as I understand is this
Static variables are usually shared between instances. And if we take example of ConnectionPool then it would be difficult if seperate instance is created each time. The idea of pooling is lost.
But I think it is different in the case of Tomcat in that webapps/project/Web-inf/classes is the place where we place the beans (like Connectionpool). Hence it cannot be a reason for slowing down the system.
please refer the classloader documentation of Tomcat.
A Classloader is created for each webapplication. All unpacked classes in the webapplicatio/Web-inf/classes are thus loaded. As a general case for all other webservers we have a separate servlet directory and the classes directory.
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

The thing is, if you put the connection pooling classes in the webapp directory, then the pool is only available to that single web-app.

For Tomcat 3.x: <TOMCAT_HOME>/lib
For Tomcat 4.x: <CATALINA_HOME>/common/lib

These directories are the 'common' directories where Tomcat will load up and use classes for *all* web apps. This is where I put my database drivers (for example). I've never used connection pooling, but I suspect putting them here would not be harmful.

The other thing about your quoted source from the web.. this is obviously a fairly old quote. "a special directory, typically named servlets". This is a lazy, and 'bad' way of doing servlets. And the description of how the classloader works in this directory is not how it works in Tomcat webapps directories.
Don't get me started about those stupid light bulbs.
subject: Where To Place Connection Pool Classes