Java Code Examples for java.lang.management.ManagementFactory.getClassLoadingMXBean()

The following are Jave code examples for showing how to use getClassLoadingMXBean() of the java.lang.management.ManagementFactory class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: swage   File: ClassLoadingSensor.java   View Source Code Vote up 5 votes
@Override
public void sense(final MetricRecorder.Context metricContext)
{
    ClassLoadingMXBean mxBean = ManagementFactory.getClassLoadingMXBean();

    metricContext.record(CURRENT_COUNT, mxBean.getLoadedClassCount(), Unit.NONE);
    metricContext.record(TOTAL_COUNT, mxBean.getTotalLoadedClassCount(), Unit.NONE);
    metricContext.record(UNLOADED_COUNT, mxBean.getUnloadedClassCount(), Unit.NONE);
}
 
Example 2
Project: micrometer   File: ClassLoaderMetrics.java   View Source Code Vote up 5 votes
@Override
public void bindTo(MeterRegistry registry) {
    ClassLoadingMXBean classLoadingBean = ManagementFactory.getClassLoadingMXBean();

    Gauge.builder("jvm.classes.loaded", classLoadingBean, ClassLoadingMXBean::getLoadedClassCount)
        .tags(tags)
        .description("The number of classes that are currently loaded in the Java virtual machine")
        .register(registry);

    FunctionCounter.builder("jvm.classes.unloaded", classLoadingBean, ClassLoadingMXBean::getUnloadedClassCount)
        .tags(tags)
        .description("The total number of classes unloaded since the Java virtual machine has started execution")
        .register(registry);
}
 
Example 3
Project: uavstack   File: JVMStateCapHandler.java   View Source Code Vote up 5 votes
private void readClassLoadUsage(MonitorElementInstance instance) {

        ClassLoadingMXBean clmb = ManagementFactory.getClassLoadingMXBean();

        instance.setValue("class_total", clmb.getTotalLoadedClassCount());
        instance.setValue("class_load", clmb.getLoadedClassCount());
        instance.setValue("class_unload", clmb.getUnloadedClassCount());
    }
 
Example 4
Project: incubator-netbeans   File: DiagnosticTask.java   View Source Code Vote up 4 votes
private String logParams() {
        StringBuilder sb = new StringBuilder(500);
        sb.append("Diagnostic information\n");
        try {
            RuntimeMXBean         rmBean     = ManagementFactory.getRuntimeMXBean();
            CompilationMXBean     cmpMBean   = ManagementFactory.getCompilationMXBean();
//            ThreadMXBean          tmBean     = ManagementFactory.getThreadMXBean();
            MemoryMXBean          memoryBean = ManagementFactory.getMemoryMXBean();
            ClassLoadingMXBean    clMBean    = ManagementFactory.getClassLoadingMXBean();

//            MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
//            ObjectName hsDiag = new ObjectName("com.sun.management:name=HotSpotDiagnostic");
//            com.sun.management.OperatingSystemMXBean sunOSMBean  =
//               ManagementFactory.getSunOperatingSystemMXBean();

//            Map<String, String> props = new TreeMap<String, String>(rmBean.getSystemProperties());
//            System.out.println("System properties");
//            for (Map.Entry<String, String> entry: props.entrySet()) {
//                System.out.println("Property: "+entry.getKey()+" Value: "+entry.getValue());
//            }
            sb.append("Input arguments:");
            for (String s: rmBean.getInputArguments()) {
                sb.append("\n\t").append(s);
            }
            
            if (cmpMBean != null) {
                sb.append("\nCompiler: "+cmpMBean.getName()).append('\n');
            }
            
            // Memory
            MemoryUsage usage = memoryBean.getHeapMemoryUsage();
            logMemoryUsage(sb, usage, "Heap memory");
            usage = memoryBean.getNonHeapMemoryUsage();
            logMemoryUsage(sb, usage, "Non heap memory");
            for (GarbageCollectorMXBean gcMBean: ManagementFactory.getGarbageCollectorMXBeans()) {
                sb.append("Garbage collector: ").append(gcMBean.getName())
                        .append(" (Collections=").append(gcMBean.getCollectionCount())
                        .append(" Total time spent=").append(formatTime(gcMBean.getCollectionTime()))
                        .append(")\n");
            }
            
            // classes
            int clsLoaded;
            long clsTotal, clsUnloaded;
            clsLoaded = clMBean.getLoadedClassCount();
            clsTotal = clMBean.getTotalLoadedClassCount();
            clsUnloaded = clMBean.getUnloadedClassCount();
            sb.append("Classes: loaded=").append(clsLoaded)
                    .append(" total loaded=").append(clsTotal)
                    .append(" unloaded ").append(clsUnloaded).append('\n');

//        } catch (MalformedObjectNameException ex) {
//            Logger.getLogger("global").log(Level.WARNING, null, ex);
        } catch (NullPointerException ex) {
            LOG.log(Level.WARNING, null, ex);
        }
        return sb.toString();
    }
 
Example 5
Project: incubator-netbeans   File: Classes.java   View Source Code Vote up 4 votes
/** Should be called at earliest possible time */
public static void initialize() {
    classLoadingBean = ManagementFactory.getClassLoadingMXBean();
}
 
Example 6
Project: util4j   File: TestJmx.java   View Source Code Vote up 4 votes
private void setFactory() {
 mxbean = ManagementFactory.getRuntimeMXBean();
 // 以下是取得虚拟机的属性
 System.out.println("===============虚拟机信息===================");
 System.out.println("虚拟机提供商:" + mxbean.getVmVendor());
 System.out.println("虚拟机名称:" + mxbean.getVmName());
 System.out.println("当前类路径:" + mxbean.getClassPath());
 System.out.println("进程号@机器:" + mxbean.getName());
 System.out.println("运行时间(毫秒):" + mxbean.getUptime());

 // 类管理接口
 System.out.println("===============类加载信息===================");
 ClassLoadingMXBean aClassLoadingMXBean = ManagementFactory
   .getClassLoadingMXBean();
 System.out.println("已加载类总数:"
   + aClassLoadingMXBean.getLoadedClassCount());
 System.out.println("Verbose状态:" + aClassLoadingMXBean.isVerbose());

 // 内存管理接口
 System.out.println("===============内存信息=====================");
 MemoryMXBean aMemoryMXBean = ManagementFactory.getMemoryMXBean();
 System.out.println("终止被挂起数:"
   + aMemoryMXBean.getObjectPendingFinalizationCount());// 返回其终止被挂起的对象的近似数目
 // 返回 Java 虚拟机使用的非堆内存的当前使用量
 MemoryUsage aMemoryUsage = aMemoryMXBean.getNonHeapMemoryUsage(); // 虚拟机启动时从系统得到的内存(以字节为单位)
 System.out.println("虚拟机启动时从系统得到的内存:" + aMemoryUsage.getInit()); // 表示当前已经使用的内存量(以字节为单位)
 System.out.println("当前已经使用的内存量:" + aMemoryUsage.getUsed()); // 表示保证可以由
 // Java
 // 虚拟机使用的内存量(以字节为单位)

 System.out.println("虚拟机使用的内存量:" + aMemoryUsage.getCommitted()); // 表示可以用于内存管理的最大内存量(以字节为单位)
 System.out.println("内存管理的初始内存量:" + aMemoryUsage.getInit());
 System.out.println("内存管理的最大内存量:" + aMemoryUsage.getMax());
 System.out.println("总体描述:" + aMemoryUsage.toString());
 
 java.util.List<GarbageCollectorMXBean> aGCMXBeans = ManagementFactory.getGarbageCollectorMXBeans();
 GarbageCollectorMXBean aGCMXBean = aGCMXBeans.get(0);
 System.out.println("===============GC信息=====================");
 System.out.println("收集总数:" + aGCMXBean.getCollectionCount());
 System.out.println("收集时间:" + aGCMXBean.getCollectionTime());
 System.out.println("内存管理器有效:" + aGCMXBean.isValid());
 System.out.println("内存池名:" + aGCMXBean.getMemoryPoolNames()[0]);
 System.out.println("内存池名:" + aGCMXBean.getMemoryPoolNames()[1]);
 
 
 System.out.println("*****************End**********************");
}
 
Example 7
Project: OpenJSharp   File: JvmClassLoadingImpl.java   View Source Code Vote up 4 votes
static ClassLoadingMXBean getClassLoadingMXBean() {
    return ManagementFactory.getClassLoadingMXBean();
}
 
Example 8
Project: jdk8u-jdk   File: JvmClassLoadingImpl.java   View Source Code Vote up 4 votes
static ClassLoadingMXBean getClassLoadingMXBean() {
    return ManagementFactory.getClassLoadingMXBean();
}
 
Example 9
Project: java-performance   File: ClassLoading.java   View Source Code Vote up 4 votes
public static void main(String[] args) {
    ClassLoadingMXBean classLoadingMXBean = ManagementFactory.getClassLoadingMXBean();
    System.out.println("Loaded classes: " + classLoadingMXBean.getLoadedClassCount());
    System.out.println("Total loaded classes: " + classLoadingMXBean.getTotalLoadedClassCount());
    System.out.println("Unloaded classes: " + classLoadingMXBean.getUnloadedClassCount());
}