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

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

问题描述

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

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

但是,然后我从命令行运行顶部,它显示

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的ram使用?有什么想法发生了什么?

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天全站免登陆