This week's book giveaway is in the OCMJEA forum. We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line! See this thread for details.
I knew that Java doesn't have API for measure CPU Usage. I have already found .dll written in C , then using JNI to communicate with it. But the problem is that I just can use that .dll in Windows. Do you know any library that I can use in Linux? Thanks very much
If you are willing to use Runtime.exec(), you can call "vmstat". (or mpstat) The last set of fields provide info on the cpu usage. Just make sure that you use a count of more than one, as the first datapoint is a long term average -- not useful to get current usage.
If you insist on JNI, you can use the library that is used by "vmstat". I believe this is implemented by a set of kernal statistic calls -- kstat library calls. However, I would not be surprised if Linux also provides a /proc FS to the cpu usage data too. You will have to check the man pages for your particular Linux OS.