Runtime runtime = Runtime.getRuntime(); long freeMemory = runtime.freeMemory(); long totalMemory = runtime.totalMemory(); long maxMemory = runtime.maxMemory(); boolean ok = (maxMemory - (totalMemory - freeMemory) > 2048); // 剩余空间小于2M报警 String msg = "Max:" + (maxMemory / 1024 / 1024) + "M, Total:" + (totalMemory / 1024 / 1024) + "M, Free:" + (freeMemory / 1024 / 1024) + "M, Use:" + ((totalMemory / 1024 / 1024) - (freeMemory / 1024 / 1024)) + "M";
虚拟机的内存状态
最新推荐文章于 2023-05-18 15:08:00 发布