Java.lang.OutOfMemoryError:Java堆空间[Ubuntu]

Java.lang.OutOfMemoryError:Java堆空间[Ubuntu],java,java-8,jvm,hybris,Java,Java 8,Jvm,Hybris,我正在尝试运行我的代码,我在控制台上遇到了这个错误 [java] Caused by: java.lang.OutOfMemoryError: Java heap space 我在jdk文件夹上运行Jconsole,最大堆1.9m,如何更改它?您可以使用-Xmx size命令行参数配置最大堆大小。 默认为64mb。你看到的1.9米看起来很奇怪 以下是java命令的Oracle文档: 具体而言: -Xmxsize Specifies the maximum size (in bytes) o

我正在尝试运行我的代码,我在控制台上遇到了这个错误

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

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

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

以下是java命令的Oracle文档:

具体而言:

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

对于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}"

我尝试使用java-xmx4064,但得到的
最大堆大小无效:-Xmx错误:无法创建java虚拟机。错误:发生致命异常。程序将退出。
更新了答案,其中包含一个链接,指向
-Xmx
用法的文档和实际文档。