标签:tps csdn virt article ota bean log virtual opera
原文链接:https://blog.csdn.net/CallMeV6/article/details/83176840
import java.lang.management.ManagementFactory; import com.sun.management.OperatingSystemMXBean; private static OperatingSystemMXBean osmxb = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean(); public static int cpuLoad() { double cpuLoad = osmxb.getSystemCpuLoad(); int percentCpuLoad = (int) (cpuLoad * 100); return percentCpuLoad; }
注意:JDK必须是1.8及以上的
返回的值是CPU的百分比,取的是整数值
import java.lang.management.ManagementFactory; import com.sun.management.OperatingSystemMXBean; private static OperatingSystemMXBean osmxb = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean(); public static int memoryLoad() { double totalvirtualMemory = osmxb.getTotalPhysicalMemorySize(); double freePhysicalMemorySize = osmxb.getFreePhysicalMemorySize(); double value = freePhysicalMemorySize/totalvirtualMemory; int percentMemoryLoad = (int) ((1-value)*100); return percentMemoryLoad; }
注意:JDK为1.6及以上版本
返回的值是内存的百分比,取的是整数值
标签:tps csdn virt article ota bean log virtual opera
原文地址:https://www.cnblogs.com/lshan/p/11681804.html