Wednesday, November 2, 2011

Class Loadres


Class loading

Class loaders are part of the Java virtual machine (JVM) code and are responsible for finding and loading class files. Class loaders enable applications that are deployed on servers to access repositories of available classes and resources. Application developers and deployers must consider the location of class and resource files, and the class loaders used to access those files, to make the files available to deployed applications.

 Class loaders affect the packaging of applications and the runtime behavior of packaged applications of deployed applications
Class loaders

The runtime environment of WebSphere Application Server uses the following class loaders to find and load new classes for an application in the following order:
1.    The bootstrap, extensions, and CLASSPATH class loaders created by the Java virtual machine
A.   Bootstrap: uses the boot class path (typically classes in jre/lib) to find and load classes.
B.    Extensions: uses the system property java.ext.dirs (typically jre/lib/ext) to find and load classes.
C.    CLASSPATH: class loader uses the CLASSPATH environment variable to find and load classes. The CLASSPATH class loader loads the Java 2 Platform, Enterprise Edition (J2EE) application programming interfaces (APIs) provided by the WebSphere Application Server product in the j2ee.jar file
2.      WebSphere extensions class loader
A.   The WebSphere extensions class loader loads the WebSphere Application Server classes that are required at run time. This class loader uses a ws.ext.dirs system property to determine the path that is used to load classes. Each directory in the ws.ext.dirs class path and every Java archive (JAR) file or ZIP file in these directories is added to the class path used by this class loader.
B.   The WebSphere extensions class loader also loads resource provider classes into a server if an application module installed on the server refers to a resource that is associated with the provider and if the provider specifies the directory name of the resource drivers.
3.    Application module class loaders
A.   The application elements can be Web modules, enterprise bean (EJB) modules, resource adapter archives (RAR files), and dependency JAR files. Application class loaders follow J2EE class-loading rules to load classes and JAR files from an enterprise application
4.    Web module class loaders
A.   Web module class loaders load the contents of the WEB-INF/classes and WEB-INF/lib directories. Web module class loaders are children of application class loaders.

Class loaders used and the order of use




                  
   A.   Each class loader is a child of the previous class loader. That is, the application  module class loaders are children of the WebSphere extensions class loader, which  is  a child of the CLASSPATH Java class loader.
B.   Whenever a class needs to be loaded, the class loader usually delegates the request to its parent class loader. If none of the parent class loaders can find the class, the original class loader attempts to load the class. Requests can only go to a parent class loader; they cannot go to a child class loader.
C.    If the WebSphere extensions class loader is requested to find a class in a J2EE module, it cannot go to the application module class loader to find that class and a ClassNotFoundException error occurs.
D.    After a class is loaded by a class loader, any new classes that it tries to load reuse the same class loader or go up the precedence list until the class is found.

Class loader mode:
1.    Parent first (Also known as Classes loaded with parent class loader 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.
2.    Parent last(Also known as Classes loaded with application class loader first):
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.

No comments:

Post a Comment