how to measure CPU usage using Java?

I would like to be able to get the CPU usage reported in the jconsole usisng Java

3 Answers

  • Anonymous
    7 years ago
    Favorite Answer

    Programmatically querying for CPU usage is impossible using pure Java. There is simply no API for this. A suggested alternative might use Runtime.exec() to determine the JVM's process ID (PID), call an external, platform-specific command like ps, and parse its output for the PID of interest.

  • Anonymous
    7 years ago

    The best way is to download Ccleaner here

    Or you can go on Windows operating system locate the command prompt and go there to do the following:

    Create a Recovery file of system and date it today.

    Then begin by;

    delete the 'Temp' folders..they have hidden subfolders so you need to set the attributes in order to bypass this. For each subfolder delete all cookies and rubbish left behnd after install-uninstalled programs. Do a 'dir' command to check your progress. Make sure the 'Temp' file is empty.

    goto c:\windows\prefetch and delete everything in exceptions

    goto c:\windows folder and delete all the '$' files that have been installed by updates. They can all be succesfully deleted and just take up disk space.

    Locate the Internet Temporary Files..Check to see how high the saving level is..some have it set at 30 days..but that stores faaaar tooo much data..though it slows down the system overal. Keep this to a minimum..suggest 2 or 5 at most.

    Delete all 'cookies' all those you don't need.

    Locate the windows directory and go through the folders you know and those you don't need. Check this once a week at least. Some programs will install under XP as NT and older systems where there is no check of systems weight.

    Check to see that system files have not changed since last booting. Things like .ini files or .bat are important items.

    Check for 'Hidden Directories' all over the this at the command prompt:

    dir *.* /ah wil show these hidden directories

    Check the 'dir' command for all parameters

  • Leo D
    Lv 6
    7 years ago

    Here is the JConsole API:

    I haven't tried it before, but it looks like you can use JConsolePlugin .addContextPropertyChangeListener to add a property change listener, which shouldn't be hard to work with if you're familiar with JavaBean :)

Still have questions? Get your answers by asking now.