Java 8 - Xmx 和 XX:MaxHeapSize 不匹配

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

Java 8 - Xmx and XX:MaxHeapSize do not match

javatomcatheap

提问by ankit.ag.in

I have set the Xmx parameter for JVM to 5120 but when the java process(tomcat) runs, I see that the MaxHeapSize does not match the Xmx value, it is stuck at 2570, which is strange to me, any thoughts on this are much appreciated!!

我已经将JVM的Xmx参数设置为5120,但是当java进程(tomcat)运行时,我看到MaxHeapSize与Xmx值不匹配,它卡在2570,这对我来说很奇怪,对此有很多想法赞赏!!

Output of ps:

ps的输出:

/usr/bin/java -Dnop -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Xms1536m -Xmx5120 -Dorg.apache.catalina.STRICT_SERVLET_COMPLIANCE=true -Djava.net.preferIPv4Stack=true -DSHUTDOWN_PORT=8005 -DHTTP_PORT=8080 -DHTTPS_PORT=8443 -DAJP_PORT=8009 -XX:InitialHeapSize=2570m -XX:MaxHeapSize=2570m -XX:MetaspaceSize=256m -XX:MaxMetaspaceSize=512m -XX:+DisableExplicitGC -Djava.endorsed.dirs=/usr/local/tomcat/endorsed -classpath /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar -Dcatalina.base=/app/tomcat/default -Dcatalina.home=/usr/local/tomcat -Djava.io.tmpdir=/app/tomcat/default/temp org.apache.catalina.

/usr/bin/java -Dnop -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Xms1536m -Xmx5120 -Dorg.apache.catalina.STRICT_SERVLET_COMPLIANCE=true -Djava.net.preferIPv4Stack=true -DSHUT5DOWN_PORT=800 -DHTTP_PORT=8080 -DHTTPS_PORT=8443 -DAJP_PORT=8009 -XX:InitialHeapSize=2570m -XX:MaxHeapSize=2570m -XX:MetaspaceSize=256m -XX:MaxMetaspaceSize=512m -XX:+DisableExplicitGC -Djavas.endors.endors. /local/tomcat/endorsed -classpath /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar -Dcatalina.base=/app/tomcat/default -Dcatalina.home =/usr/local/tomcat -Djava.io.tmpdir=/app/tomcat/default/temp org.apache.catalina。

回答by shizhz

Problems in your config:

您的配置中的问题:

-Xms1536m -Xmx5120

-Xms1536m -Xmx5120

If you don't specify the unit of this config, it will be parsed as bytes, which means your Xmxis less than your Xms, if this config applies JVM will failed to launch:

如果你不指定这个配置的单位,它会被解析为bytes,这意味着你Xmx的小于你的Xms,如果这个配置适用,JVM将无法启动:

? ~/ java -Xms1536m -Xmx5120 -XX:+PrintFlagsFinal -version
Error occurred during initialization of VM
Initial heap size set to a larger value than the maximum heap size

Your JVM did not aborted because you have following configs:

您的 JVM 没有中止,因为您有以下配置:

-XX:InitialHeapSize=2570m -XX:MaxHeapSize=2570m

-XX:InitialHeapSize=2570m -XX:MaxHeapSize=2570m

-Xmsis -XX:InitialHeapSizeand -Xmxis -XX:MaxHeapSize, so your previous wrong config of -Xms1536m -Xmx5120is replaced by the later ones, which specified Xmxto be 2570M.

-Xmsis-XX:InitialHeapSize-Xmxis -XX:MaxHeapSize,因此您之前的错误配置-Xms1536m -Xmx5120被替换为后来的配置,指定Xmx为 2570M。

回答by wumpz

The -Xmx option is equivalent to -XX:MaxHeapSize.

-Xmx 选项等效于 -XX:MaxHeapSize。

(https://docs.oracle.com/javase/8/docs/technotes/tools/unix/java.html)

( https://docs.oracle.com/javase/8/docs/technotes/tools/unix/java.html)

So -Xmx5120means 5120 Bytesbut is superseeded by -XX:MaxHeapSize=2570m. That is the reason you are stuck by this.

所以-Xmx5120意味着5120 字节,但被-XX:MaxHeapSize=2570m. 这就是你被这个卡住的原因。

Just provide only one of these settings and choose the proper value, e.g.

只需提供这些设置之一并选择适当的值,例如

-Xmx5120m