Friday, December 7, 2018

Class Loaders & Websphere

Class loader is an object responsible for loading classes and its an abstract class itself.

Whenever we make a java project , we have a .java file which after compilation becomes a platform independent byte code i.e .class. Then JVM loads this .class in memory and execute it.

So, there are three java loaders:

  • Bootstrap Class Loader :  It Loads internal JDK classes from jre/lib
  • Extension Class Loader : It loads jar from jre/lib/ext 
  • Application/System Class Loader: It loads classes from classpath or defined path
Image result for class loader in java
Ways of loading classes:

  • Delegation Principle: Any request to load class will be given preference to parent class, if parent cant load then only the child gets to respond. (as you can see in picture above)
  • Uniqueness: At any point of time only one type/copy of class is available to be loaded,. so , if a class is loaded by parent it wont be loaded by its child.
  • Visibility: Child classes have visibility of all classes loaded by parent.
Configuring Classloader in Websphere

  • Click Servers > Server Types > WebSphere application servers > server_name to access an application server settings page.
  • Specify the application class-loader policy for the application server.The application class-loader policy controls the isolation of applications that run in the system (on the server). An application class loader groups enterprise bean (EJB) modules, shared libraries, resource adapter archives (RAR files), and dependency Java archive (JAR) files associated to an application. Dependency JAR files are JAR files that contain code which can be used by both enterprise beans and servlets. The application class-loader policy controls whether an application class loader can be shared by multiple applications or is unique for each application.
Use the application server settings page to specify the application class-loader policy for the server:
OptionDescription
SingleApplications are not isolated from each other. Uses a single application class loader to load all of the EJB modules, shared libraries, and dependency JAR files in the system.
MultipleApplications are isolated from each other. Gives each application its own class loader to load the EJB modules, shared libraries, and dependency JAR files of that application.
  • Specify the application class-loader mode for the application server.The application class loading mode specifies the class-loader mode when the application class-loader policy is Single.On the application server settings page, select either of the following values:

OptionDescription
Classes loaded with parent class loader firstCauses 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. Classes loaded with parent class loader first is the default value for class loading mode.
This value is also known as parent first.
Classes loaded with local class loader first (parent last)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.
  • Specify the class-loader mode for the class loader.
  1. On the application server settings page, click Java and Process Management > Class loader to access the Class loader page.
  2. On the Class loader page, click New to access the settings page for a class loader.
  3. On the class loader settings page, specify the class loader order.The Classes loaded with parent class loader first value 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.The Classes loaded with local class loader first (parent last) value causes the class loader to attempt to load classes from its local class path before delegating the class loading to its parent.
  4. Click OK
An identifier is assigned to a class-loader instance. The instance is added to the collection of class loaders shown on the Class loader page.


This is cleared a lot of things for me regarding classloader. I hope it helps you too.

No comments:

Post a Comment