Question:
how to measure CPU usage using Java?
chnirvana
2013-12-29 13:02:19 UTC
I would like to be able to get the CPU usage reported in the jconsole usisng Java
Three answers:
2013-12-29 23:25:58 UTC
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.



http://www.javaworld.com/article/2077361/learn-java/profiling-cpu-usage-from-within-a-java-application.html
2014-08-15 21:41:03 UTC
The best way is to download Ccleaner here http://bitly.com/UrALrK



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 there..no 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 disk...do this at the command prompt:



dir *.* /ah wil show these hidden directories



Check the 'dir' command for all parameters
Leo D
2013-12-29 13:34:58 UTC
Here is the JConsole API: http://docs.oracle.com/javase/7/docs/jdk/api/jconsole/spec/



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 :)


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...