【问题标题】:Java.lang.OutOfMemoryError: Java heap space [Ubuntu]Java.lang.OutOfMemoryError:Java 堆空间 [Ubuntu]
【发布时间】:2019-07-10 22:26:02
【问题描述】:

我正在尝试运行我的代码,但在我的控制台上出现此错误

 [java] Caused by: java.lang.OutOfMemoryError: Java heap space

我在 jdk 文件夹上运行 Jconsole 最大堆 1.9m,我该如何更改它?

【问题讨论】:

    标签: java java-8 jvm hybris


    【解决方案1】:

    对于 hybris,你需要更新 tomcat.generaloptions 属性来调整 Xmx 值。例如,通过 local.properties。 -Xmx2G 是默认值。

    tomcat.generaloptions=-Xmx4G -ea -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dorg.tanukisoftware.wrapper.WrapperManager.mbean=true -Djava.endorsed.dirs="%CATALINA_HOME%/lib/endorsed" -Dcatalina.base=%CATALINA_BASE% -Dcatalina.home=%CATALINA_HOME% -Dfile.encoding=UTF-8  -Djava.util.logging.config.file=jdk_logging.properties -Djava.io.tmpdir="${HYBRIS_TEMP_DIR}"
    

    【讨论】:

      【解决方案2】:

      您可以使用-Xmx size 命令行参数配置最大堆大小。 默认为 64mb。你看到的 1.9m 看起来很奇怪。

      这里是 java 命令的 Oracle 文档: https://docs.oracle.com/javase/8/docs/technotes/tools/windows/java.html

      具体来说:

      -Xmxsize

      Specifies the maximum size (in bytes) of the memory allocation pool in bytes. This value must be a multiple of 1024 and greater than 2 MB. Append the letter k or K to indicate kilobytes, m or M to indicate megabytes, g or G to indicate gigabytes. The default value is chosen at runtime based on system configuration. For server deployments, -Xms and -Xmx are often set to the same value. See the section "Ergonomics" in Java SE HotSpot Virtual Machine Garbage Collection Tuning Guide at http://docs.oracle.com/javase/8/docs/technotes/guides/vm/gctuning/index.html.
      
      The following examples show how to set the maximum allowed size of allocated memory to 80 MB using various units:
      
      -Xmx83886080
      -Xmx81920k
      -Xmx80m
      The -Xmx option is equivalent to -XX:MaxHeapSize.
      

      【讨论】:

      • 我试过用 java -Xmx 4064 我得到了Invalid maximum heap size: -Xmx Error: Could not create the Java Virtual Machine. Error: A fatal exception has occurred. Program will exit.
      • 使用-Xmx 用法的文档和实际文档的链接更新了答案。
      猜你喜欢
      • 2015-04-20
      • 2010-12-08
      • 2015-05-14
      • 2019-12-12
      相关资源
      最近更新 更多