InfoCenter Home > 6.4.1.2: ClassLoadersWhile running, each application server constructs a hierarchy of ClassLoaders. As the diagram indicates, there is a single instance of the application server JVM ClassLoader at the top, followed by a single instance of a JARClassLoader, followed by multiple instances of the PowerClassLoaders (one per Web Application). Search orderThe order of searching for a class is from the top of the hierarchy to the bottom:
Suppose you have a class named MyClass. The ClassLoader for the first classpath in which MyClass is encountered becomes the ClassLoader for MyClass. All classes referenced from MyClass will be loaded by this ClassLoader or any of its ancestors. Classes referencing classes loaded by other classLoadersClasses loaded by a particular ClassLoader can reference other classes as long as these other classes can be loaded by the same ClassLoader or any of its ancestors (but not its children). Suppose an EJB class is loaded by the JARClassLoader and a servlet class is loaded by the PowerClassLoader. Imagine that the servlet invokes an EJB method and passes it a class as an argument. This class should be accessible to both the EJB class and the servlet class. If this class is kept in the Web application classpath, then the JARClassLoader will not be able to access it because the PowerClassLoader is a child of the JARClassLoader. However, if this class is kept in the EJB JAR classpath then both the JARClassLoader and the PowerClassLoader will be able to access it. Web application isolationThe relationship among the ClassLoaders also implies that it is not possible to access the classes of one Web application from another Web application, if the JAR files for the two Web Applications are kept in different Web application classpaths (meaning they are loaded by two different PowerClassLoaders). This allows isolating Web applications from one another. However, all EJB classes are accessible from each other when the application server containing them is running (but not during EJB deployment).
|
| ||||||||||||||||||||||||||||||||||||||||||||||||||
|