我有一个课程如下:
class MyClass
{
public static void main(String args[])
{
//I want statistics here
}
}
任何帮助都将不胜感激。
答案 0 :(得分:0)
运行时运行时= Runtime.getRuntime();
NumberFormat format = NumberFormat.getInstance();
StringBuilder sb = new StringBuilder();
long maxMemory = runtime.maxMemory();
long allocatedMemory = runtime.totalMemory();
long freeMemory = runtime.freeMemory();
sb.append("free memory: " + format.format(freeMemory / 1024) + "<br/>");
sb.append("allocated memory: " + format.format(allocatedMemory / 1024) + "<br/>");
sb.append("max memory: " + format.format(maxMemory / 1024) + "<br/>");
sb.append("total free memory: " + format.format((freeMemory + (maxMemory - allocatedMemory)) / 1024) + "<br/>");
答案 1 :(得分:0)
MemoryMXBean包含所有可用的内存数据。这包括有关堆和非堆内存的数据。 Runtime
类仅提供对堆内存信息的访问。