Atitit. The implementation of java c #. net php node. js that gets the cpu share,

Source: Internet
Author: User

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

 

Related Article

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.