Java Runtime.maxMemory 不正确吗? [英] Java Runtime.maxMemory incorrect?

查看:20
本文介绍了Java Runtime.maxMemory 不正确吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我运行了以下方法Runtime.getRuntime().maxMemory()并给了85196800.

I ran the following method Runtime.getRuntime().maxMemory() and gave 85196800.

但是,然后我从命令行运行 top 并显示

However, I then ran top from the command line and it showed

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                                                                                                       
 8672 root      20   0 1284m 156m 4296 S  0.3 60.9   0:33.35 java        

这不是显示使用了 156M 的内存吗?知道发生了什么吗?

Doesn't that show 156M of ram used? Any ideas what is going on?

推荐答案

来自文档,

maxMemory() -返回 Java 虚拟机将尝试使用的最大内存量.

maxMemory() - Returns the maximum amount of memory that the Java virtual machine will attempt to use.

Top 仅显示系统分配给进程的(虚拟)内存量 - 您问 Java 在最坏的情况下它可以尝试使用多少.

Top only shows the amount of (virtual) memory that the system has allocated to the process - you are asking Java how much it could attempt to use in the worst case.

通常,查询 JVM 和/或系统以获取有关实际使用内存的信息是不可靠的.例如,top 的数字可能包括已分配但未使用或调出的内存.它还可以包括共享库之类的东西,其中一个 10MB 的库可能会计算两个进程的分配,但内存中只有一个物理副本.(例如)

In general, querying the JVM and/or system for information on actual memory used is not reliable. For example, top's numbers may include memory allocated but not used or paged out. It can also include things like shared libraries, where a 10MB library may count for two processes' allocations but only have one physical copy in memory. (For example)

你想做什么?

这篇关于Java Runtime.maxMemory 不正确吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆