Class Loaders
1. Class Loader Types
· The bootstrap, extensions, and CLASSPATH class loaders created by the Java virtual machine
· A WebSphere extensions class loader
· One or more application module class loaders that load elements of enterprise applications running in the server
· Zero or more Web module class loaders
Important Notes:
· Each class loader is a child of the previous class loader.
· Requests can only go to a parent class loader; they cannot go to a child loader. If WebSphere extensions class loader is requested to find a class in Application module class loader, a ClassNotFoundException occurs.
2. Class loader isolation policies
Two class-loader policies control the isolation of applications and modules:
Class-loader scope | Class loader policy | Description | Where to set? |
Application | Single: applications are not isolated | Application class loaders load EJB modules, dependency JAR files, embedded resource adapters, and application-scoped shared libraries. Depending on the application class-loader policy, an application class loader can be shared by multiple applications (Single) or unique for each application (Multiple). The application class-loader policy controls the isolation of applications that are running in the system. | On the WAS Admin Console, navigate to Servers -> Application Server, select the AppServer where your application will run. On the configuration tab, you will see the Classloader policy combo box. |
Multiple: applications are isolated from each other. | |||
WAR | Application: the Web module contents also are loaded by the application class loader | By default, Web module class loaders load the contents of the WEB-INF/classes and WEB-INF/lib directories. The application class loader is the parent of the Web module class loader. You can change the default behavior by changing the Web application archive (WAR) class-loader policy of the application. The WAR class-loader policy controls the isolation of Web modules. | · Admin Console->Applications-> Enterprise Applications, select the application you want. On the configuration, you will see the WAR class loader policy. · Or, on the workspace,you could open the Application Deployment Descriptor, go to Deployment -> Application. In the Applications list, select the EAR file, on the right side, you could see the WAR class loader policy. |
Module: each Web module receives its own class loader whose parent is the application class loader |
3. Class loader modes
Two values for a class-loader mode are supported:
Class-loader mode | Description |
Parent first | The Parent first class-loader mode causes the class loader to delegate the loading of classes to its parent class loader before attempting to load the class from its local class path. This value is the default for the class-loader policy and for standard JVM class loaders. |
Parent last | The Parent last class-loader mode causes the class loader to attempt to load classes from its local class path before delegating the class loading to its parent. Using this policy, an application class loader can override and provide its own version of a class that exists in the parent class loader. |
The following settings determine the mode of a class loader:
- If the application class-loader policy of an application server is Single, the server-level mode value defines the mode for an application class loader.
- If the application class-loader policy of an application server is Multiple, the application-level mode value defines the mode for an application class loader.
- If the WAR class-loader policy of an application is Module, the module-level mode value defines the mode for a WAR class loader.
Class loader scope | Where to set |
WebSphere extentions | Admin Cosole->Servers->Application Servers->..->Class loading mode
|
Application extentions | ? (Not sure )Admin Cosole->Servers->Application Servers->..->Java and Process Management -> Class loader ->
|
Application module | · Admin Cosole ->Applications-> Enterprise Applications->..->Class loader mode · Application Deployment Descriptor->Deployment->Application |
Web Module | · Admin Cosole ->Applications-> Enterprise Applications->..->Web modules ->..->Class loader mode · Application Deployment Descriptor->Deployment->Application |
to be continued ...
Resources:
Shared Libraries: WAS6 InfoCenter (Setting up the application serving environment->Administrating application servers-> Managing shared libraries)
Class Loaders: WAS6 InfoCenter (Developing and deploying applications->Class loading)
Classloading in WebSphere Portal: WebSphere Portal InfoCenter (Developing portlets->Portlet development basics->Creating a simple portlet)