Home  >  Core Java

Example of CompilationMXBean in Java

By Arvind Rai, March 25, 2013
CompilationMXBean is the interface which consist the methods to get just-in-time compiler information. CompilationMXBean belongs to the package java.lang.management. In JVM only one instance of CompilationMXBean will be available. The object of CompilationMXBean can be obtained a
 CompilationMXBean clMxBean = ManagementFactory.getCompilationMXBean();
Find the sample example to use the CompilationMXBean.
CompilationMXBeanTest.java
package com.concretepage;
import java.lang.management.CompilationMXBean;
import java.lang.management.ManagementFactory;
public class CompilationMXBeanTest {
  class UserThread extends Thread {
      public void run() {        
             CompilationMXBean clMxBean = ManagementFactory.getCompilationMXBean();
             //returns the name of just-in-time compiler
             System.out.println("just-in-time compiler name:"+clMxBean.getName());
             //gets time spent in compilation
             System.out.println("TotalCompilationTime:"+clMxBean.getTotalCompilationTime());
      }
  }
  public static void main(String[] a){
      Thread th= new CompilationMXBeanTest().new UserThread();
      Runtime.getRuntime().addShutdownHook(th);
  }
}
Output
just-in-time compiler name:HotSpot 64-Bit Tiered Compilers
TotalCompilationTime:6 
POSTED BY
ARVIND RAI
ARVIND RAI
FIND MORE TUTORILAS






©2019 concretepage.com | Privacy Policy | Contact Us