我正在运行某个 Java 程序,其 -Xmx
高于 -Xms
,即它的堆可以增长。执行结束时的堆大小 (IIRC) 不是运行期间使用的最大值。
- 如何获取当前堆大小?
- 除了定期“我自己”轮询当前大小之外,我如何才能在运行过程中获得最大堆大小?
最佳答案
获取当前堆大小:
public static long getHeapSize(){
int mb = 1024*1024;
//Getting the runtime reference from system
Runtime runtime = Runtime.getRuntime();
return ((runtime.totalMemory() - runtime.freeMemory()) / mb);
}
关于java - Java 程序如何跟踪其运行期间使用的最大实际堆大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14937381/