CPU Usage
Call the ManagementFactory.getOperatingSystemMXBean() method to obtain information about the CPU usage.
Example:
import Java.lang.management.ManagementFactory;
import com.sun.management.OperatingSystemMXBean;
public class SystemProperty {
public static void main(String args[]) {
OperatingSystemMXBean osmxb = (OperatingSystemMXBean) ManagementF
actory.getOperatingSystemMXBean();
double cpuLoad = osmxb.getSystemCpuLoad();
System.out.println("cpuLoad: " + cpuLoad);
}
Execution result on the Kunpeng platform:
[root@centos7 test]# Java SystemProperty cpuLoad: 0
Parent topic: Java