Atitit. Implementation of Java C #. NET PHP node. js for getting CPU share

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.