Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: How to get a System's total CPU usage percentage using a java program

  1. #1
    Junior Member
    Join Date
    Jan 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question How to get a System's total CPU usage percentage using a java program

    Hi,

    I need to find the system's total CPU usage percentage ( as we see in Windows Task Manager) using a java program. I am able to find the CPU usage time for one process using the OperatingSystemMXBean API. But i am not able to find a way to find the CPU usage percentage for all the process running on a system.
    I cannut use any third party tools to acheive this. Are there any third party jars available which can help me in getting this data?

    Thanks


  2. #2
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,895
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: How to get a System's total CPU usage percentage using a java program

    I don't think it's possible in pure Java. You'll either need to use a 3rd party package, or write your own.

    One that I've heard of (but never used personally) is called the SIGAR API. It should get you what you want.

    To write your own, you'll need to understand how to get these values using another language (possibly C/C++) and then interface that library with your Java code using JNI. Note that different operating systems will use different methods to get these values so you'll need to write a separate library to get support across multiple operating systems.

    Further reading: How to monitor the computer's cpu, memory, and disk usage in Java? - Stack Overflow
    Last edited by helloworld922; January 7th, 2011 at 01:04 AM.

  3. #3
    Member
    Join Date
    Dec 2010
    Posts
    46
    Thanks
    0
    Thanked 10 Times in 10 Posts

    Default Re: How to get a System's total CPU usage percentage using a java program

    you can also try WMI using Java.

    you can seean example of how its done using vbscript. Then adapt the WMI code portion with Java.

Similar Threads

  1. Find total number less than average
    By maximus20895 in forum Collections and Generics
    Replies: 2
    Last Post: December 1st, 2010, 01:46 PM
  2. It's not printing out the correct percentage...
    By JBow94 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 15th, 2010, 04:07 PM
  3. Eclipse is always locked [High CPU & RAM usage]
    By talha06 in forum Java IDEs
    Replies: 4
    Last Post: March 16th, 2010, 10:07 AM
  4. No Percentage?
    By chronoz13 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: December 18th, 2009, 12:02 PM
  5. HashMap usage in Java
    By neo_2010 in forum Collections and Generics
    Replies: 2
    Last Post: September 18th, 2009, 02:12 AM