Java堆空间Xmx Xms参数被忽略 [英] Java heap space Xmx Xms parameters ignored

查看:122
本文介绍了Java堆空间Xmx Xms参数被忽略的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个.JAR,它显然占用了过多的内存,并引发了异常"Java堆空间"(或类似的东西).

I have a .JAR that apparently uses up too much memory, and throws an exception "Java heap space" (or something similar).

所以我尝试通过CMD运行.JAR,如下所示:

So I tried running the .JAR via the CMD like this:

C:\MyFolder>javaw -jar MyJar.jar -Xms64m -Xmx128m

那并不能解决问题.同样的错误. 现在,当我检查Windows任务管理器中的进程"选项卡时,我注意到我的jar进程的内存比我要求的要少得多(与不带参数运行它一样).

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).

为什么忽略参数?

此外,我认为在进程达到100mb的内存使用量时会引发异常. GC是否有可能试图释放内存,这是导致问题的原因?我可以为GC设置任何参数来防止这种情况吗?

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?

谢谢,马尔基:)

推荐答案

命令

javaw -jar MyJar.jar -Xms64m -Xmx128m

将使用-Xms ...和-Xmx ...作为"main(String [] args)"方法的参数.
必须在-jar部分之前将参数 to 传递给JVM:

will use -Xms... and -Xmx... as parameters to the "main(String[] args)" method.
Parameters to the JVM must be passed before the -jar part:

javaw -Xms64m -Xmx128m -jar MyJar.jar

执行"java -version"可以看到原因:

The reason for that can be seen when we execute "java -version" :

Usage: java [-options] class [args...]
           (to execute a class)
   or  java [-options] -jar jarfile [args...]
           (to execute a jar file)

您的参数-Xms ...和-Xmx ...是JVM的选项.

Where your parameters -Xms... and -Xmx... are options to the JVM.

这篇关于Java堆空间Xmx Xms参数被忽略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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