Atitit. Get CPU Share of Java C #. NET PHP node. js the implementation
gain CPU share via WMIC interface
C:\users\administrator.attilaxpc188>wmic CPU Get Loadpercentage
Loadpercentage
71
Note: Average CPU usage is calculated
all we get is the instantaneous CPU usage, which takes a while for the average CPU to be better
/atiplat_cms/src/com/attilax/device/calcor.java
second, get the CPU,is the total CPU, if you need to accurately guide each core occupancy, you can also use the detailed version of this command.
In addition, this WMIC interface is not able to get a numeric value when the CPU is busy, and may be an os problem. Strategy..
author:: Nickname :Old Wow's claws( Full Name::AttilaxAkbar Al Rapanui Attilaksachanui)
Kanji Name: Etila ( Ayron) , email:[email protected]
reprint Please indicate source: http://www.cnblogs.com/attilax/
Lower CPU consumption
use sleep technology best suited. Can control the number of threadPool tasks in disguise.
public static int getcpurate () throws cantgetdata {
String getcpurate = "WMIC CPU get Loadpercentage" ;
String ret = cmdx. exec (getcpurate);
logger "--wmic CPU:" ret );
string[] a = ret . Split ("\ n");
list<string> Li = Lists. newarraylist ();
for (String string : a) {
String Line = string . Trim ();
if (line. Length () = = 0)
Continue ;
Li . Add (line);
}
String CPU = NULL ;
if (li. Size () = = 1)
Throw New cantgetdata (ret);
//String CPU = Li.get (Li.size ()-1);
try {
CPU = Li . Get (1). toString (). Trim ();
} catch (Exception e) {
throw new
// }
return Integer. parseint (CPU. toString ());
}
Resources
Java_threadmxbean_api Home , the largest Chinese API Community . html
JAVA gets the CPU usage of this process -csdn question and answer . html
(4) cpu _ memory usage _ _ _ Sina blog .html
(5) How Java gets CPU usage and hard disk occupancy _ Baidu knows . html (Good )
Atiend
Atitit. Implementation of Java C #. NET PHP node. js for getting CPU share