Troubleshooting classloader issues with WebSphere

What is a Classloader:

ClassLoader is the central entity of Java Virtual Machine. It is responsible for loading the classes into the JVM.

The ClassLoader class uses a delegation model to search for classes and resources. Each instance of ClassLoader has an associated parent class loader. When requested to find a class or resource, a ClassLoader instance will delegate the search for the class or resource to its parent class loader before attempting to find the class or resource itself. The virtual machine’s built-in class loader, called the “bootstrap class loader”, does not itself have a parent but may serve as the parent of a ClassLoader instance.

There are few basic classloaders:

  1. Bootstrap classloader : It is JVM’s built in classloader that loads core classes like java.lang etc. The bootstrap class loader uses the boot class path (typically classes in jre/lib) to find and load classes.
  2. System classloader: Loads the classes in the java classpath
  3. A WebSphere extensions class loader : Loads the classes from ws.ext.dirs class path
  4. Application classloaders : Used by the enterprise applications to load classes from the application itself for ex. Jar files, ejb modules etc.
  5. Zero or more Web module class loaders : These loads the contents from  WEB-INF/classes and WEB-INF/lib directories.

Troubleshooting classloading issues in any environment is an invariably tedious process.

There could be exceptions like ClassNotFoundException Exceptions, NoClassDefFoundErrors in your application. You can use the approaches to troubleshoot these issues

1. Using the classloader viewer:

WebSphere has a very good built tool to view class loaders visible to a Web module (.war file) or enterprise bean (.ejb file) in an installed enterprise application. It helps you to determine which class loaders loaded files of a module and to diagnose problems with class loaders.

To access the same, you need to click on the <Server-Name>  –> Under the Additional properties tab –> Click on the ‘Class Loader Viewer Service’

 

 

Enable the checkbox  as below:

 

This would require restart of the server.

Then you can view the detailed report by navigating to  Troubleshooting tab from the left panel  –> Class Loader Viewer  –>  Select the application you would like to monitor.

 

2. You can enable the verbose classloading on the server:

It specifies whether to use verbose debug output for class loading. The default is not to enable verbose class loading.

Login into the WebSphere Admin console –> Click on the server on which you want to enable verbose classloader –> Click on Process Definition  under the Server Infrastructure management –> Click on Java Virtual Machine –> Enable the Verbose Class loading option.

 

 

 

 

3:  Another way you can debug classloader issues is to enable debug for “com.ibm.ws.classloader.*”.

 

Click on the Server –>Click on the Change Log Detail Levels and define the class on which you would like to enable the logging level.

 

 

Further reading:

http://publib.boulder.ibm.com/infocenter/ieduasst/v1r1m0/index.jsp?topic=/com.ibm.iea.was_v6/was/6.0/Runtime/WASv6_ClassLoader_PD/player.html

 

Cheers,

Team Wonders.