在java語言中,每個java應用程序都有一個Runtime類實例,Runtime類提供了多個查看內存使用情況的方法,如下例所示:
public class Test { public static void main(String[] args) { // 得到JVM中的空閑內存量(單位是字節) System.out.println(Runtime.getRuntime().freeMemory()); // 的JVM內存總量(單位是字節) System.out.println(Runtime.getRuntime().totalMemory()); // JVM試圖使用額最大內存量(單位是字節) System.out.println(Runtime.getRuntime().maxMemory()); // 可用處理器的數目 System.out.println(Runtime.getRuntime().availableProcessors()); } }
運行結果:
本文轉載自:https://blog.csdn.net/Marmara01/article/details/85225308