[英]Java: Memory usage issue
我已将maxmimum memory设置为此值
java -Xmx280m -jar ...
内存使用信息代码(点击按钮):
int mb = 1024*1024;
//Getting the runtime reference from system
Runtime runtime = Runtime.getRuntime();
System.out.println("##### Heap utilization statistics [MB] #####");
//Print used memory
System.out.println("Used Memory:"
+ (runtime.totalMemory() - runtime.freeMemory()) / mb);
//Print free memory
System.out.println("Free Memory:"
+ runtime.freeMemory() / mb);
//Print total available memory
System.out.println("Total Memory:" + runtime.totalMemory() / mb);
//Print Maximum available memory
System.out.println("Max Memory:" + runtime.maxMemory() / mb);
该程序显示以下输出(2次点击+新标签等):
Used Memory:41
Free Memory:123
Total Memory:165
Max Memory:249
Used Memory:67
Free Memory:97
Total Memory:165
Max Memory:249
但是,当我查看Linux(Centos 7)系统监视器时,它显示了这个java进程的330mb
。 怎么解释呢?
JVM内存包含以下部分:
可以使用在进程启动期间传递的标志配置这些部分:
您指定的280兆字节是为Java程序的堆保留的。 VM和其他东西也使用内存,因此它在命令行和进程列表中永远不会是相同的数字。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.