首页 > 代码库 > Java中的CPU和系统负载监控——OperatingSystemMXBean

Java中的CPU和系统负载监控——OperatingSystemMXBean

    在JAVA 7中,可以使用OperatingSystemMXBean类对系统和CPU负载情况进行监控

方法如下:

import com.sun.management.OperatingSystemMXBean;
...
OperatingSystemMXBean osBean = ManagementFactory.getPlatformMXBean(OperatingSystemMXBean.class);
// What % CPU load this current JVM is taking, from 0.0-1.0
System.out.println(osBean.getProcessCpuLoad());//指CPU的负载情况

// What % load the overall system is at, from 0.0-1.0
System.out.println(osBean.getSystemCpuLoad());//指系统的负载情况

注意:getSystemLoadAverage()在JAVA 6也有,但可惜的是在WINDOWS上运行的并不好

 

参考 http://blog.csdn.net/jackyrongvip/article/details/6646358

Java中的CPU和系统负载监控——OperatingSystemMXBean