1) Bootstrap Class Loader. 2) Extensions Class Loader. 3) Application Class Loader.
WAS also provides the option to create a custom class loader if the options provided out of the box don’t match the requirements of the application. In addition to custom class loaders, WAS also provides isolated class loaders for Shared libraries. So what exactly is a “class loader”? A class loader is a part of the Java virtual machine (JVM) that loads classes into memory; a class loader is responsible for finding and loading class files at run time. When you start a JVM, you use three class loaders:- The bootstrap class loader is responsible for loading only the core Java libraries in the Java_home/jre/lib directory. This class loader, which is part of the core JVM, is written in native code.
- The extensions class loader is responsible for loading the code in the extensions directories (Java_home/jre/lib/ext or any other directory specified by the java.ext.dirs system property). This class loader is implemented by the sun.misc.Launcher$ExtClassLoader class.
- The application class loader is responsible for loading code that is found on java.class.path, which ultimately maps to the system CLASSPATH variable. This class loader is implemented by the sun.misc.Launcher$AppClassLoader class.
The IBM WAS Redbook can be found at the following URL: http://www.redbooks.ibm.com/redpapers/pdfs/redp4581.pdf
If the parent class loader cannot load the class, the child class loader tries to find the class in its own repository. In this manner, a class loader is only responsible for loading classes that its ancestors cannot load. However, this may not always be what you need for your program. To provide flexibility, one of the features that WAS provides is the ability to change the class loader delegation behavior. It can either be PARENT_FIRST (the default behavior) or can be modified to PARENT_LAST.
- PARENT_FIRST 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.
- PARENT_LAST causes the class loader to attempt to load classes from its local class path before delegating the class loading to its parent.
1) Create a separate file (for example, Resource.jar), configure it as a utility JAR, move all log4j.properties files from the modules into this file, and make their names unique (like war1-1_log4j.properties, war1-2_log4j.properties, and ejb1_log4j.properties). When initializing log4j from each module, tell it to load the proper configuration file for the module instead of the default log4j.properties.
2) Keep the log4j.properties for the Web modules in their original place (/WEB-INF/classes), add log4j.jar to both Web modules (/WEB-INF/lib) and set the class loading mode for the Web modules to Classes loaded with local class loader first (PARENT_LAST). When initializing log4j from a Web module, it loads the log4j.jar from the module itself and log4j would find the log4j.properties on its local classpath, the Web module itself. When the EJB module initializes log4j, it loads from the application class loader and it finds the log4j.properties file in its own class path and loads the log4j.jar from its own class path.
In conclusion, the ability to set class loader policies and to manage them at a micro level shows us the extent to which applications deployed on WAS can be customized. There is absolutely no parallel to the flexibility provided by WAS when it comes to application management.