Results 1 to 5 of 5
  1. #1
    javaxoty is offline Member
    Join Date
    Apr 2014
    Posts
    2
    Rep Power
    0

    Default Get Computer CPU Usage

    Hello,

    I am new to Java Forums but glad to be here.

    I am pretty noob to Java and Eclipse. Please go easy with me.

    I want to get current Computer CPU usage of my computer and display it in Console View of Eclipse? How can I achieve this?

    My template code is:

    Java Code:
        public class GetCPUUsage{  
            public static void main(String[] args){  
              
                System.out.println("CPU USAGE IS: ??????");  
              
            }  
        }
    I added ??? as placeholder for CPU usage because I do not know how to retrieve RAM usage by Java. I hope I could express myself more clearly this time. If not please let me know.

    Cheers

  2. #2
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,365
    Rep Power
    6

    Default Re: Get Computer CPU Usage

    Google: "java get cpu usage"
    Result: jmx - How to get percentage of CPU usage of OS from java - Stack Overflow

    There isn't really any "get cpu usage" method to call, its very operating system specific and Java does not do operating system specific things. Probably a better idea is to invoke a shell command from the Java application and parse its output, but that depends on the OS you want this to run on.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  3. #3
    javaxoty is offline Member
    Join Date
    Apr 2014
    Posts
    2
    Rep Power
    0

    Default Re: Get Computer CPU Usage

    Quote Originally Posted by gimbal2 View Post
    Google: "java get cpu usage"
    Result: jmx - How to get percentage of CPU usage of OS from java - Stack Overflow

    There isn't really any "get cpu usage" method to call, its very operating system specific and Java does not do operating system specific things. Probably a better idea is to invoke a shell command from the Java application and parse its output, but that depends on the OS you want this to run on.
    Hi gimbal2,

    Thank you very much for your reply.

    Because I am new to programming and Java, I need some code examples so that I can learn how things work, say how can I import JAVA API and third party libraries in Eclipse? Would you mind posting the code listing to get CPU usage please? I just gawk at the conversation and code in stackoverflow.

    Cheers

  4. #4
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,365
    Rep Power
    6

    Default Re: Get Computer CPU Usage

    ... you didn't read any of what I said apparently.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default Re: Get Computer CPU Usage

    Quote Originally Posted by javaxoty View Post
    Hi gimbal2,

    Thank you very much for your reply.

    Because I am new to programming and Java, I need some code examples so that I can learn how things work, say how can I import JAVA API and third party libraries in Eclipse? Would you mind posting the code listing to get CPU usage please? I just gawk at the conversation and code in stackoverflow.

    Cheers
    You've picked something that (for Java) is quite complex, especially if you are new and find the conversations on StackOverflow beyond you. I would recommend finding something else to develop.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. usage of array..
    By passionlrnr in forum New To Java
    Replies: 2
    Last Post: 11-11-2012, 08:21 PM
  2. CPU usage without JNI
    By Eranga in forum Advanced Java
    Replies: 2
    Last Post: 12-13-2011, 03:25 AM
  3. multipart usage
    By shreya in forum Advanced Java
    Replies: 2
    Last Post: 04-06-2010, 04:26 AM
  4. Usage of List
    By vasavi.singh in forum New To Java
    Replies: 0
    Last Post: 03-12-2009, 03:51 PM
  5. Need help with AST usage on Eclipse! Thanks!
    By j_aquino314 in forum Eclipse
    Replies: 0
    Last Post: 10-08-2008, 08:15 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •