无法为 Java 分配足够的堆空间

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5788356/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 12:45:47  来源:igfitidea点击:

Could not allocate enough heap space to Java

javamemorymemory-managementgarbage-collectionwindows-server-2003

提问by Eric Taix

We have an application which was running fine for one year. It is a web application, running under Tomcat 5.5 + JDK 1.5 under Microsoft Cluster on Windows Server 2003 Enterprise Edition Service Pack 2. The server has 11Gb of RAM (I know that it is useless!) with the following description "Physical Address Extension": I don't know what that means.

我们有一个应用程序运行了一年。它是一个 Web 应用程序,在 Windows Server 2003 Enterprise Edition Service Pack 2 上的 Microsoft Cluster 下的 Tomcat 5.5 + JDK 1.5 下运行。该服务器有 11Gb 的 RAM(我知道它没用!)并带有以下描述“物理地址扩展” : 不知道什么意思。

The Tomcat service is configured with the following parameters: -Xmx1024m -Xms128m

Tomcat 服务配置了以下参数: -Xmx1024m -Xms128m

Since last week, the service doesn't want to start anymore and stops with the following error message: "Could not allocate enough heap space".

自上周以来,该服务不想再启动并停止并显示以下错误消息:“无法分配足够的堆空间”。

We tried several tests:

我们尝试了几个测试:

  • java -Xmx1024m -version=> Failed
  • java -Xmx758m -version=> Failed
  • java -Xmx512m -version=> Passed
  • java -Xmx1024m -version=> 失败
  • java -Xmx758m -version=> 失败
  • java -Xmx512m -version=> 通过

So we can use less memory for the maximum heap size, but it is not an acceptable workaround because the number of users will increase in few months and we need to set the maximum heap size to 1024Mb.

所以我们可以为最大堆大小使用更少的内存,但这不是一个可以接受的解决方法,因为用户数会在几个月内增加,我们需要将最大堆大小设置为 1024Mb。

Also I don't understand why it worked fine and then suddenly it stopped working! It seems that the OS is now unable to allocate contiguous memory, or something else (page file size, user memory allocation, ...)

我也不明白为什么它工作正常,然后突然停止工作!似乎操作系统现在无法分配连续内存或其他内容(页面文件大小、用户内存分配……)

It's quite difficult to know if something changed (OS patch, configuration, ...) because the web application is running on the customer server and we don't have access to it.

很难知道某些内容是否发生了变化(操作系统补丁、配置等),因为 Web 应用程序正在客户服务器上运行,而我们无权访问它。

回答by Peter Lawrey

Java requires continous memory. On 32-bit OSes this limits you to between 1.2 and 1.4 GB on Windows. However if your memory is fragmented due to other programs which are running, you might get a much smaller region of memory.

Java 需要连续内存。在 32 位操作系统上,这将您限制在 1.2 到 1.4 GB 之间(在 Windows 上)。但是,如果您的内存因其他正在运行的程序而碎片化,您可能会获得更小的内存区域。

You won't get this problem with a 64-bit OS and you can even allocate far more memory to the jVM as well (if you use a 64-bit JVM)

你不会在 64 位操作系统上遇到这个问题,你甚至可以为 JVM 分配更多的内存(如果你使用 64 位 JVM)

回答by Eric Taix

I've got some news about my problem.

我有一些关于我的问题的消息。

This seems to be due to a Windows security update ! This Microsoft security update prevents java applications to allocate a large amount of contiguous memory...

这似乎是由于 Windows 安全更新!此 Microsoft 安全更新可防止 Java 应用程序分配大量连续内存...

More information here: http://support.microsoft.com/kb/971812

更多信息请访问:http: //support.microsoft.com/kb/971812

We will check if the patch solves this problem. Stay tuned

我们将检查补丁是否解决了这个问题。敬请关注

回答by Thomas

Also I don't understand why it worked fine and suddenly it stopped to work ! It seems that the OS is now unable to allocate contiguous memory, or something else (page file size, user memory allocation, ...)

It's quite difficult to know if something changed (OS patch, configuration, ...) because the web application is running on the customer server and we have no access to it.

我也不明白为什么它工作正常,突然停止工作!似乎操作系统现在无法分配连续内存或其他内容(页面文件大小、用户内存分配……)

很难知道某些内容是否发生了变化(操作系统补丁、配置等),因为 Web 应用程序正在客户服务器上运行,而我们无法访问它。

Well, you should check how much memory is available and if it's not enough, you should check what is consuming that much memory.

好吧,您应该检查有多少内存可用,如果不够,您应该检查是什么消耗了这么多内存。

Other than that, you'd have to talk to your customer and find out if they did changes to the server and if so, what they did change.

除此之外,您必须与您的客户交谈并了解他们是否对服务器进行了更改,如果是,他们做了哪些更改。

Without knowing more it's really hard up to impossible to give any qualified advice on why you can't allocate more memory.

在不了解更多信息的情况下,很难就为什么不能分配更多内存提供任何合格的建议。

回答by Denis Tulskiy

It probably means the OS can not allocate enough continuous memory. Do you still have the problem after OS restart? Does the system report it has 11 Gb of RAM? Windows's implementation of PAE is not the best one, so it could cause problems. Try updating to a newer JDK, if that fails, you'd need a 64-bit machine.

这可能意味着操作系统无法分配足够的连续内存。操作系统重启后问题仍然存在吗?系统是否报告它有 11 Gb 的 RAM?Windows 的 PAE 实现并不是最好的,因此可能会导致问题。尝试更新到较新的 JDK,如果失败,则需要 64 位机器。