12.3.1 Class loader policies
For each appserver in the system, the class loader policy can be set to Single or Multiple.
When the appserver class loader policy is set to Single, a single application class loader is used to load all EJBs, utility JARs, and shared libraries within the appserver (JVM). If the WAR class loader policy then has been set to Single class loader for application (or Application), the Web module contents for this particular application are also loaded by this single class loader.
When the appserver class loader policy is set to Multiple, the default, each application will receive its own class loader for loading EJBs, utility JARs, and shared libraries. Depending on whether the WAR class loader loading policy is set to Class loader for each WAR file in application (or Module) or Single class loader for application (or Application), the Web module might or might not receive its own class loader.
Here is an example to illustrate. You have two applications, Application1 and Application2, running in the same appserver. Each application has one EJB module, one utility JAR, and two Web modules. If the appserver has its class loader policy set to Multiple, the default, and the class loader policy for all the Web modules are set to use a class loader for each WAR file in application (Module), also the default, the result is as shown in Figure 12-3.
Figure 12-3 Class loader policies: Example 1
Each application is completely separated from the other and each Web module is also completely separated from the other one in the same application. WebSphere's default class loader policies results in total isolation between the applications and the modules.
If we now change the class loader policy for the WAR2-2 module from Class loader for each WAR file in application (Module) to Single class loader for application (Application), the result is shown in Figure 12-4.
Figure 12-4 Class loader policies: Example 2
Web module WAR2-2 is loaded by Application2's class loader and classes, for example, in Util2.jar, are able to see classes in WAR2-2's /WEB-INF/classes and /WEB-INF/lib directories.
As a last example, if we change the class loader policy for the appserver from Multiple to Single and also change the class loader policy for WAR2-1 from Class loader for each WAR file in application (Module) to Single class loader for application (Application), the result is as shown in Figure 12-5.
Figure 12-5 Class loader policies: Example 3
There is now only a single application class loader loading classes for both Application1 and Application2. Classes in Util1.jar can see classes in EJB2.jar, Util2.jar, WAR2-1.war and WAR2-2.war. The classes loaded by the application class loader still cannot, however, see the classes in the WAR1-1 and WAR1-2 modules, because a class loader can only find classes by going up the hierarchy, never down.