java java堆空间问题,如何增加堆大小?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2229990/
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-29 20:10:47  来源:igfitidea点击:

Problems with java heap space, how to increas the heap size?

javaheapout-of-memory

提问by Ikky

I'm running a ".bat" file which points to asant:

我正在运行一个指向 asant 的“.bat”文件:

C:\Sun\SDK\bin\asant Startbds

asant again points to a xml file i've got, build.xml:

asant 再次指向我得到的 xml 文件 build.xml:

<target name="Startbds" description="Start bds">

This has been fine for now, but now i have added more data, which leads to an out of memory error:

这暂时没问题,但现在我添加了更多数据,这导致了内存不足错误:

java.lang.outOfMemoryError: Java heap space

So i've tried to increase the heap space by various methods i've found while searching around for a solution:

因此,我尝试通过在四处寻找解决方案时发现的各种方法来增加堆空间:

  • cmd: set ANT_OPTS=-Xms512m -Xmx512m(did not work, same error message)
  • Editing the asant.bat where i edited the line "-set ANT_OPTS" from
  • cmd: set ANT_OPTS=-Xms512m -Xmx512m(不起作用,同样的错误信息)
  • 编辑 asant.bat,我从中编辑了“-set ANT_OPTS”行

.

.

set ANT_OPTS="-Dos.name=Windows_NT" -Djava.library.path=%AS_INSTALL%\lib;%AS_ICU_LIB%;%AS_NSS%" "-Dcom.sun.aas.installRoot=%AS_INSTALL%" "-Dcom.sun.aas.instanceRoot=%AS_INSTALL%" "-Dcom.sun.aas.instanceName=server" "-Dcom.sun.aas.configRoot=%AS_CONFIG%" "-Dcom.sun.aas.processLauncher=SE" "-Dderby.root=%AS_DERBY_INSTALL%"  

TO

set ANT_OPTS="-Xms512m -Xmx512m" "-Dos.name=Windows_NT" -Djava.library.path=%AS_INSTALL%\lib;%AS_ICU_LIB%;%AS_NSS%" "-Dcom.sun.aas.installRoot=%AS_INSTALL%" "-Dcom.sun.aas.instanceRoot=%AS_INSTALL%" "-Dcom.sun.aas.instanceName=server" "-Dcom.sun.aas.configRoot=%AS_CONFIG%" "-Dcom.sun.aas.processLauncher=SE" "-Dderby.root=%AS_DERBY_INSTALL%"  

but this gave me the error message:

但这给了我错误信息:

"Invalid initial heap size: -Xms512m -Xmx512m
 Could not create the Java virtual machine."

Anyone got an idea of how i should increase the heapsize? And maybe also give a pointer to where i can find a tool to watch the heapsize.

有人知道我应该如何增加堆大小吗?也许还可以指出我在哪里可以找到观察堆大小的工具。

Thanks in advance.

提前致谢。

回答by Joachim Sauer

By using "-Xms512m -Xmx512m"you gave a single argument. -Xmsexpects the minimum heap size to be specified by the rest of the argument. So you defined the minimum heap size to be "512m -Xmx512m", which is not a valid value.

通过使用"-Xms512m -Xmx512m"你给出了一个论点-Xms期望由参数的其余部分指定最小堆大小。因此,您将最小堆大小定义为“512m -Xmx512m”,这不是有效值。

You will want to provide those switches as two arguments:

您需要将这些开关作为两个参数提供

set ANT_OPTS=-Xms512m -Xmx512m "-Dos.name=Windows_NT" ...

回答by Uri

I think that if you're in windows, you don't need the double quotes in your set. Here is an example I saw somewhere:

我认为如果你在 Windows 中,你不需要在你的集合中使用双引号。这是我在某处看到的一个例子:

set ANT_OPTS=-Xms512m -Xmx512m  (Windows)
export ANT_OPTS="-Xms512m -Xmx512m"  (ksh/bash)
setenv ANT_OPTS "-Xms512m -Xmx512m"  (tcsh/csh)

As for monitoring heap usage, if you are using the most recent JDK on Windows, you should have Sun's VisualVM.

至于监控堆使用情况,如果你在 Windows 上使用最新的 JDK,你应该有 Sun 的 VisualVM。

回答by jean chen

in eclipse-> window->preferences->Tomcat->JVM Setting->Append to JVM Parameters

在 eclipse-> window->preferences->Tomcat->JVM Setting->Append to JVM Parameters

-XX:MaxPermSize=512m

-XX:MaxPermSize=512m

-Xms512m

-Xms512m

-Xmx512m

-Xmx512m