Atitit. The implementation of java c #. net php node. js that gets the cpu share,
Atitit. java c #. net php node. js implementation for obtaining cpu share
Obtain the cpu share through the wmic Interface
C: \ Users \ Administrator. ATTILAXPC188> wmic cpu get LoadPercentage
LoadPercentage
71
Note: Average cpu usage Calculation
All we get is instantaneous cpu usage, and it takes a period of time for average cpu usage to be better.
/Atiplat_cms/src/com/attilax/device/Calcor. java
Second, the obtained cpu is the total cpu. If you need to precisely guide the occupation of each core, you can also use the detailed version of this command.
In addition, the wmic interface cannot obtain the value when the cpu is busy, which may be an OS problem. Policy ..
Author: nickname: old wow's paw (full name: Attilax Akbar Al Rapanui Attila Akba Arla Panui)
Chinese name: atira (iron), EMAIL: 1466519819@qq.com
Reprinted please indicate Source: http://www.cnblogs.com/attilax/
Reduce cpu usage
Sleep is the most suitable technology. You can control the number of threadPool tasks in disguise.
Public Static IntGetCpuRate ()ThrowsCantGetData {
String getCpuRate = "wmic cpu get LoadPercentage ";
String ret = bytes X.Exec(GetCpuRate );
Logger. Info ("-- wmic cpu:" + ret );
String [] a = ret. split ("\ n ");
List <String> li = Lists.NewArrayList();
For(String string: ){
String line = string. trim ();
If(Line. length () = 0)
Continue;
Li. add (line );
}
String cpu =Null;
If(Li. size () = 1)
Throw NewCantGetData (ret );
// String cpu = li. get (li. size ()-1 );
// Try {
Cpu = li. get (1). toString (). trim ();
//} Catch (Exception e ){
// Throw new
//}
ReturnInteger.ParseInt(Cpu. toString ());
}
References
Java_threadmxbean_api's home.
JAVA requires the CPU usage rate of the local import -csdn .html
(4) Java receives the CPU usage rate, memory usage rate, and hard disk usage rate.
(How can I obtain CPU usage and hard disk usage for Java on the 5th node)
Atiend