Friday, September 16, 2011

Weblogic:Classloading and Classloader Analysis Tool


There is a Classloading Analysis Tool(CAT) provided in Weblogic server(PS3) which helps you to monitor the class loading pattern that happens with an application. It helps you in identifying any class loading issues that can happen due to different java classes that are duplicated with different libraries. To understand the use of CAT, you should first know the class loading pattern in Weblogic.
Classloading in Weblogic happens in different levels.The below image shows the hierarchy in which the class loading happens
System classloader is the top-level classloader that loads the WebLogic implementation classes and supporting libraries defined on the classpath (those added to setDomanEnv and commEnv) 
Domain level classloader is a child to the SYSTEM classloader and loads libraries that are included in the domain lib directory.
Application level classloader is the next in order.  WebLogic Server automatically creates a hierarchy of classloaders when an application is deployed. The root classloader in this hierarchy is the APPLICATION classloader and it loads modules defined in the application, including EJBs, as well as java EE shared libraries and libraries included in the configured library directories for the application.
For each web application, a child class loader is created and it loads the shared Java EE libraries as well as the libraries and compiled classes in the WEB-INF folder.

What happens if the CAT find issues in the class loading pattern of the application
WebLogic has  a feature called the Filtering ClassLoader which overrides the TOP-DOWN classloading and essentially enables child-first classloading.  When filter is enabled, priority is given to the resources from the child of the FilteringClassLoader (an application classloader) before the ones from the system classloader . This will be mainly used when the version used by systme class loader or top level class loaders are different from the one required by the application.
Usage(in weblogic.xml)
<prefer-application-packages>
          <package-name>geo.*</package-name>
</prefer-application-packages>


How to use  CAT?
Login to http://host:port/wls-cat/ and enter your credentials.


- Analyze classloading conflicts
- View the system and application classloaders
- Generate reports



CAT will suggest you solutions to overcome the conflicts which is also a good feature.
Below references give you detailed explanation on weblogic class loading as well as fetures involved in CAT tool.
References: 
  1. CAT tool
  2. Class Loading by Jeff West






No comments: