java获取windowscpu使用率方法
1、第一步:判断系统,linux,windons,mac等等系统使用命令和方法都不一样。代码如下:// 操作系统String osName = System.getProperty("os.name");

3、第三步:获取cpu信息,命令和代码如下:String procCmd = System.getenv("windir") + "//system32//wbem//wmic.exe process get Caption,CommandLine," + "KernelModeTime,ReadOperationCount,ThreadCount,UserModeTime,WriteOperationCount";// 取进程信息long[] c0 = readCpu(Runtime.getRuntime().exec(procCmd));

5、第五步:构造对象,对返回的结果进行封装,代码如下:// 构造返回对象MonitorInfoBean infoBean = new MonitorInfoBean();infoBean.setFreeMemory(freeMemory);infoBean.setFreePhysicalMemorySize(freePhysicalMemorySize);infoBean.setMaxMemory(maxMemory);infoBean.setOsName(osName);infoBean.setTotalMemory(totalMemory);infoBean.setTotalMemorySize(totalMemorySize);infoBean.setTotalThread(totalThread);infoBean.setUsedMemory(usedMemory);infoBean.setCpuRatio(cpuRatio);

7、第七步:运行结果展示,如图:

8、第八步:此放不了网盘地址,要的留言