Meaningless Drivel is fun!*
The moose likes Beginning Java and the fly likes instances of  Class loaders ??? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "instances of  Class loaders ???" Watch "instances of  Class loaders ???" New topic
Author

instances of Class loaders ???

A Kumar
Ranch Hand

Joined: Jul 04, 2004
Posts: 979
Hi,

Suppose I have a web server(say tomcat) and there are 3 web applications...then how many class loaders are present and how many JVMS...

Tx in advance,
Regards
Chris Beckey
Ranch Hand

Joined: Jun 09, 2006
Posts: 116

One JVM.
The number of classloaders depends on the app (or web) server. For Tomcat there is one classloader per web app. A parent class loader of the web app classloaders is "shared" by all web apps. Above that are "common", "system" and "bootstrap". An additional "catalina" classloader is a child of "common". The JVM has at least one additional classloader and more likely three.
So if you have three webapps then you have at least 9 and probably more like 11 class loaders total.
In Tomcat the ones you probably care about are the webapp specific classloader and the "shared" classloader (for shared libraries). If you are writing realms, connectors or resources then you may also touch "common" and "catalina".
A Kumar
Ranch Hand

Joined: Jul 04, 2004
Posts: 979
Thanks Chris!!!

But how to get hold of the "shared" classloader??
[ April 10, 2007: Message edited by: A Kumar ]
Chris Beckey
Ranch Hand

Joined: Jun 09, 2006
Posts: 116

If you just need to load classes such that they are available to multiple webapps then put the classes/lib in the "shared" directory (i.e. C:\Program Files\Apache Software Foundation\Tomcat 5.5\shared on a Windows box with the default install).
If you really need a reference to the shared class loader you can get a reference to the webapp class loader (this.getClass().getClassLoader() from a servlet will do the trick) and then get its parent (getParent()).
A Kumar
Ranch Hand

Joined: Jul 04, 2004
Posts: 979
Thanks Chris!!!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: instances of Class loaders ???