Java 堆空间 Xmx Xms 参数被忽略
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3093631/
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
Java heap space Xmx Xms parameters ignored
提问by Malki
I have a .JAR that apparently uses up too much memory, and throws an exception "Java heap space" (or something similar).
我有一个 .JAR 显然占用了太多内存,并抛出异常“Java 堆空间”(或类似的东西)。
So I tried running the .JAR via the CMD like this:
所以我尝试通过 CMD 运行 .JAR,如下所示:
C:\MyFolder>javaw -jar MyJar.jar -Xms64m -Xmx128m
That did not solve the problem. Same error. Now, when I checked the Processes tab in the windows task manager, I noticed that the process of my jar has a lot less memory than what i asked for (same as running it without the parameters).
那并没有解决问题。同样的错误。现在,当我检查 Windows 任务管理器中的进程选项卡时,我注意到我的 jar 进程的内存比我要求的少得多(与不带参数运行它相同)。
Why is it ignoring the parameters?
为什么忽略参数?
Also, I think the exception is thrown around the time the process reaches 100mb of memory usage. Is it possible that the GC is trying to free up the memory and that's what causes the problem? Is there any parameter I can set for the GC to prevent that?
另外,我认为在进程达到 100mb 内存使用量时会抛出异常。是否有可能 GC 试图释放内存,这就是导致问题的原因?我可以为 GC 设置任何参数来防止这种情况发生吗?
Thanks, Malki :)
谢谢,马尔基:)
回答by Philipp
The Command
命令
javaw -jar MyJar.jar -Xms64m -Xmx128m
will use -Xms... and -Xmx... as parameters to the "main(String[] args)" method.
Parameters tothe JVM must be passed before the -jar part:
将使用 -Xms... 和 -Xmx... 作为“main(String[] args)”方法的参数。
参数到JVM中必须在罐子部分之前进行传递:
javaw -Xms64m -Xmx128m -jar MyJar.jar
The reason for that can be seen when we execute "java -version" :
当我们执行“java -version”时可以看出原因:
Usage: java [-options] class [args...]
(to execute a class)
or java [-options] -jar jarfile [args...]
(to execute a jar file)
Where your parameters -Xms... and -Xmx... are options to the JVM.
您的参数 -Xms... 和 -Xmx... 是 JVM 的选项。

