用Java查找Windows计算机的平均CPU使用率 [英] Finding the average CPU usage for Windows machine in Java

查看:409
本文介绍了用Java查找Windows计算机的平均CPU使用率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在互联网上搜索了大约两天。我发现了很多有关如何使用VB和.NET框架中的内容查找CPU使用率的信息。我感觉我没有使用.NET框架,所以它们是无关紧要的。



我真正需要的是与 CPU使用情况部分中显示的结果相似的结果。 性能选项卡下的Windows任务管理器。如果我能找到一种模仿该计算的方法,那正是我所寻找的。我需要CPU使用率的百分比。



显然,Java不是查找计算机CPU使用率的理想语言,但这是我和我正在使用的语言。



我正在使用Windows 7和Java 7更新21。Eclipse是我的IDE。



这是我第一次在此处发布问题,因此,如果我遗漏了任何东西或有不清楚的地方,请询问,我将尽力解释更多信息

解决方案

有两种方法可以做到这一点。一种是运行命令行工具并解析输出。在Windows 7上,您可以运行

  c:\Windows\system32\typeperf \processor(_total)\ processor%的处理器时间 

尝试一下-打印几行采样的CPU负载数据。 / p>

另一种方法是使用 OperatingSystemMXBean


I have searched all over the internet for about two days now. I have found a lot about how to find the CPU usage using VB and anything in the .NET framework. I am not using the .NET framework so these are irrelevant, I feel.

What I really need is results similar to the ones shown in the "CPU Usage" section in a Windows Task Manager under the "Performance" tab. If I could find a way to mimic that calculation, then that is exactly what I am looking for. I need the percentage of CPU Usage.

Obviously, Java is not the ideal language for finding the CPU usage of a computer, but that is the language I am using and I have been able to get everything else I need about the computer except this.

I am using Windows 7 with Java version 7 update 21. Eclipse is my IDE.

This is my first time posting a question on here, so if I have left anything out or something is not clear, please ask and I will do my best to explain more of what I mean.

解决方案

There are a couple of ways to do this; one is to run a command-line tool and parse the output. On Windows 7, you can run

c:\Windows\system32\typeperf "\processor(_total)\% processor time"

Try it -- it prints a few lines of sampled CPU load data.

Another way is to use OperatingSystemMXBean .

这篇关于用Java查找Windows计算机的平均CPU使用率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆