JVM ARGS '-Xms1024m -Xmx2048m' 在 Java 8 中仍然有用吗?

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

Is JVM ARGS '-Xms1024m -Xmx2048m' still useful in Java 8?

javajvmjava-8jvm-arguments

提问by coderz

I have a Java 7 application using JVM ARGS: -Xms1024m -Xmx2048m, and it runs pretty well.

我有一个使用 JVM ARGS: 的 Java 7 应用程序-Xms1024m -Xmx2048m,它运行得很好。

After I upgrade to Java 8, it runs in error state with Exception:

升级到 Java 8 后,它在错误状态下运行并出现异常:

Exception in thread "main" java.lang.OutOfMemoryError: GC overhead limit exceeded
    at org.hibernate.engine.StatefulPersistenceContext.addEntry(StatefulPersistenceContext.java:466)
    at org.hibernate.engine.TwoPhaseLoad.postHydrate(TwoPhaseLoad.java:80)
    at org.hibernate.loader.Loader.loadFromResultSet(Loader.java:1439)
    at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:1332)
    at org.hibernate.loader.Loader.getRow(Loader.java:1230)
    at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:603)
    at org.hibernate.loader.Loader.doQuery(Loader.java:724)
    at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259)
    at org.hibernate.loader.Loader.doList(Loader.java:2228)
    at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2125)
    at org.hibernate.loader.Loader.list(Loader.java:2120)
    at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:118)
    at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1596)
    at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:306)

I'm wondering whether JVM ARGS -Xms1024m -Xmx2048mis still working?

我想知道 JVM ARGS-Xms1024m -Xmx2048m是否还在工作?

Since Java 8 has removed Perm Generation: http://www.infoq.com/articles/Java-PERMGEN-Removed, I think the different GC strategy/memory management between Java 7 and Java 8 may be the root cause. Is there any suggestion?

由于 Java 8 删除了 Perm Generation:http: //www.infoq.com/articles/Java-PERMGEN-Removed,我认为 Java 7 和 Java 8 之间不同的 GC 策略/内存管理可能是根本原因。有什么建议吗?

采纳答案by Tagir Valeev

Due to PermGen removal some options were removed (like -XX:MaxPermSize), but options -Xmsand -Xmxwork in Java 8. It's possible that under Java 8 your application simply needs somewhat more memory. Try to increase -Xmxvalue. Alternatively you can try to switch to G1 garbage collector using -XX:+UseG1GC.

由于永久代删除,一些选项被删除(如-XX:MaxPermSize),但选项-Xms-Xmx在 Java 8 中工作。在 Java 8 下,您的应用程序可能只需要更多内存。尝试增加-Xmx价值。或者,您可以尝试使用-XX:+UseG1GC.

Note that if you use any option which was removed in Java 8, you will see a warning upon application start:

请注意,如果您使用在 Java 8 中删除的任何选项,您将在应用程序启动时看到警告:

$ java -XX:MaxPermSize=128M -version
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=128M; support was removed in 8.0
java version "1.8.0_25"
Java(TM) SE Runtime Environment (build 1.8.0_25-b18)
Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode)

回答by Ankur Anand

What I know is one reason when “GC overhead limit exceeded” error is thrown when 2% of the memory is freed after several GC cycles

我所知道的是在几个 GC 周期后释放 2% 的内存时抛出“超出 GC 开销限制”错误的原因之一

By this error your JVM is signalling that your application is spending too much time in garbage collection. so the little amount GC was able to clean will be quickly filled again thus forcing GC to restart the cleaning process again.

通过此错误,您的 JVM 表示您的应用程序在垃圾收集上花费了太多时间。因此,GC 能够清理的少量将再次快速填充,从而迫使 GC 再次重新启动清理过程。

You should try changing the value of -Xmxand -Xms.

你应该尝试改变的价值-Xmx-Xms