sun的标准包中只有Runtime的 freeMemory,maxMemory,totalMemory方法能返回你要的东西,但是他们返回的都是虚拟机的内存使用信息,对于cpu的信息就没办法了,如 totalMemory() Returns the total amount of memory in the Java virtual machine. 返回系统分配给虚拟机的总内存数量maxMemory() Returns the maximum amount of memory that the Java virtual machine will attempt to use. 返回虚拟机将可以调用的最大内存数量freeMemory() Returns the amount of free memory in the Java Virtual Machine. 即返回当前虚拟机空闲的内存数量所以真正要得到你要的东西只有调用系统api才行
totalMemory()
Returns the total amount of memory in the Java virtual machine.
返回系统分配给虚拟机的总内存数量maxMemory()
Returns the maximum amount of memory that the Java virtual machine will attempt to use.
返回虚拟机将可以调用的最大内存数量freeMemory()
Returns the amount of free memory in the Java Virtual Machine.
即返回当前虚拟机空闲的内存数量所以真正要得到你要的东西只有调用系统api才行
java -Xrunhprof:cpu=sample,file=prof.txt <class文件名〉
java -Xrunhprof:help得到帮助