您现在的位置:计算机技术学习网 > 技术中心 > WEB编程 > JSP >

JSP获取CPU使用率、系统内存、虚拟机内存等情况(不用JNI)(6)

来源:未知 责任编辑:责任编辑 发表时间:2014-05-26 10:59 点击:

                        .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));

发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
用户名: 验证码:点击我更换图片
最新评论 更多>>

推荐热点

  • JSP与Servlet
  • 自己动手写MiniBBS系列(基本篇)之用户登录
  • JSP取当前日期
  • JDBC 入门(一)
  • 打开一个jsp页面默认查询所有数据,调用action
  • 使用JSP标签库验证用户的输入(2)完
  • WIN98/2000下的jsp服务器
  • 自定义JSP标签(tag)浅议
  • Struts学习傻瓜式入门篇
网站首页 - 友情链接 - 网站地图 - TAG标签 - RSS订阅 - 内容搜索
Copyright © 2008-2015 计算机技术学习交流网. 版权所有

豫ICP备11007008号-1