Java 怎么使用平台MXBeans进行JVM或系统进程负载监视

2019年7月18日19:54:03 评论 58

1.简介

Java 怎么使用平台MXBeans进行JVM或系统进程负载监视?——请看下文。

2.代码

/**
 * 版权所有 编程十万个怎么办(www.tah1986.com)
 */
import java.lang.management.ManagementFactory;
import java.lang.management.OperatingSystemMXBean;
import java.lang.management.RuntimeMXBean;
import java.util.List;

public class Main {
    
    public static void main(String[] args) {
        RuntimeMXBean mxBean = ManagementFactory.getPlatformMXBean(RuntimeMXBean.class);

        System.out.println("JVM Name: " + mxBean.getName());
        System.out.println("JVM Specification Name: " + mxBean.getSpecName());
        System.out.println("JVM Specification Version: " + mxBean.getSpecVersion());
        System.out.println("JVM Implemenation Name: " + mxBean.getVmName());
        System.out.println("JVM Implemenation Vendor: " + mxBean.getVmVendor());
        System.out.println("JVM Implemenation Version: " + mxBean.getVmVersion());

        
        List<OperatingSystemMXBean> list =
                ManagementFactory.getPlatformMXBeans(OperatingSystemMXBean.class);
        System.out.println("size: " + list.size());
        for (OperatingSystemMXBean bean : list) {
            System.out.println("Operating System Name: " + bean.getName());
            System.out.println("Operating System Architecture: " + bean.getArch());
            System.out.println("Operating System Version: " + bean.getVersion());
        }
        
    }
    
}

 

3.总结

示例代码演示了 Java 怎么使用平台MXBeans进行JVM或系统进程负载监视,具体步骤参见示例代码。

  • A+
所属分类:JMX

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: