如果指定最大堆大小大于可用RAM,会发生什么 [英] What happens if you specify max heap size greater than available RAM

查看:132
本文介绍了如果指定最大堆大小大于可用RAM,会发生什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在接受采访时被问到。如果指定的最大堆大小(Xmx)大于可用RAM,会发生什么?
我也想知道如果指定最小堆大小(Xms)大于可用RAM会发生什么?

Asked in an interview. What happens if you specify max heap size (Xmx) greater than available RAM? I also wonder what happens if you specify min heap size (Xms) greater than available RAM?

推荐答案

最简单找出方法就是试试看。

The easiest way to find out is try it and see.

编辑:
问题实际上至少有两个答案。可能在64位系统上,如前所述,您的应用程序可能会在内存使用量增长和增长并开始颠簸。在32位系统上,故事有点不同,因为操作系统无法为您提供那么多堆空间。例如,如果我使用命令行选项-Xmx2000m在带有32位java的Windows XP上运行应用程序,它将会丢失一条类似于以下内容的消息:

There are actually at least two answers to the question. Probably on a 64 bit system, as was mentioned, your app could grow and grow in memory usage and start thrashing. On a 32 bit system the story is a little different because the os is not able to give you that much heap space. For instance, if I run an app on Windows XP with 32 bit java with the command line option -Xmx2000m it will die with a message similar to the following:


无效的最大堆大小:-Xmx2000m

Invalid maximum heap size: -Xmx2000m

指定的大小超过了可表示的最大大小。

The specified size exceeds the maximum representable size.

无法创建Java虚拟机。

Could not create the Java virtual machine.

在Linux中使用32 bit java,我得到以下-Xmx3000m:

In Linux with 32 bit java, I get the following with -Xmx3000m:


无法创建Java虚拟机。

Could not create the Java virtual machine.

VM初始化期间发生错误

Error occurred during initialization of VM

无法为对象堆保留足够的空间

Could not reserve enough space for object heap

在使用32位java的Linux中,我得到以下内容-Xmx6000m

In Linux with 32 bit java, I get the following with -Xmx6000m


无效的最大堆大小: - Xmx6000m

Invalid maximum heap size: -Xmx6000m

指定的大小超过了最大可表示大小。

The specified size exceeds the maximum representable size.

无法创建Java虚拟机。

Could not create the Java virtual machine.

尝试使用64位Java,JVM确实允许你分配比物理RAM更多的内存,不过如果你要求极端大量的内存,jvm将再次失败并出现错误。

Trying this with 64 bit Java, the JVM does allow you to allocate more memory than there is physical RAM, though if you ask for an extremely large amount of memory, the jvm will again fail with an error.

这篇关于如果指定最大堆大小大于可用RAM,会发生什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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