Home  >  Core Java

Example of ClassLoadingMXBean in Java

By Arvind Rai, March 25, 2013
ClassLoadingMXBean is the interface under the package java.lang.management which has the methods to give the information of class loader in JVM. The object of ClassLoadingMXBean is created as
ClassLoadingMXBean clMxBean = ManagementFactory.getClassLoadingMXBean();
In JVM only one object is created. It acts as singleton. Find the sample use of the methods of ClassLoadingMXBean.
ClassLoadingMXBeanTest.java
package com.concretepage;
import java.lang.management.ClassLoadingMXBean;
import java.lang.management.ManagementFactory;
public class ClassLoadingMXBeanTest {
  class UserThread extends Thread {
      @Override
      public void run() {
                 ClassLoadingMXBean clMxBean = ManagementFactory.getClassLoadingMXBean();
                 //gets loaded class count
                 System.out.println("LoadedClassCount:"+clMxBean.getLoadedClassCount());
                 //gets total loaded class count
                 System.out.println("TotalLoadedClassCount():"+clMxBean.getTotalLoadedClassCount());
                 //gets unloaded class count
                 System.out.println("UnloadedClassCount:"+clMxBean.getUnloadedClassCount());
      }
  }
  public static void main(String[] a){
      Thread th= new ClassLoadingMXBeanTest().new UserThread();
      Runtime.getRuntime().addShutdownHook(th);
  }
}
Output
LoadedClassCount:329
TotalLoadedClassCount():329
UnloadedClassCount:0
POSTED BY
ARVIND RAI
ARVIND RAI
FIND MORE TUTORILAS






©2019 concretepage.com | Privacy Policy | Contact Us