JSP获取CPU使用率、系统内存、虚拟机内存等情况(不用JNI)(6)
.indexOf("%")));
return (1 - usage.floatValue() / 100);
}
} catch (IOException ioe) {
System.out.println(ioe.getMessage());
freeResource(is, isr, brStat);
return 1;
} finally {
freeResource(is, isr, brStat);
}
}
private static void freeResource(InputStream is, InputStreamReader isr,
BufferedReader br) {
try {
if (is != null)
is.close();
if (isr != null)
isr.close();
if (br != null)
br.close();
} catch (IOException ioe) {
System.out.println(ioe.getMessage());
}
}
/**
* 获得CPU使用率.
*
* @return 返回cpu使用率
* @author GuoHuang
*/
private double getCpuRatioForWindows() {
try {
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));
相关新闻>>
- 发表评论
-
- 最新评论 更多>>