Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

instances of Class loaders ???

 
A Kumar
Ranch Hand
Posts: 980
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 116
Eclipse IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 980
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Chris!!!

But how to get hold of the "shared" classloader??
[ April 10, 2007: Message edited by: A Kumar ]
 
Chris Beckey
Ranch Hand
Posts: 116
Eclipse IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 980
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Chris!!!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic