我对 Linux 还很陌生(在 Windows 中也没有用过太多 cmd 行),我需要将 Java 堆大小从 850MB 增加到 3GB(机器上总共有 4GB 的 RAM)。
我浏览过几个网站,寻求有关增加堆大小的指导,但我从中获取的命令似乎都不起作用。
作为参考,我查看了:
根据这些问题中的信息,我尝试了以下命令:
java -Xmx3072m
java -Xmx3g
java JAVA_OPTS="-Xmx3g"
JAVA_OPTS="-Xmx3g"
每次执行后我都没有收到任何错误(除了第三个命令,那个命令有错误),但是当我运行'
答案1
通过
java -Xmx3072m <your_class_name>
或者
java -Xmx3072m -jar <your_jar_file>
或者
JAVA_OPTS="-Xmx3G"
java "$JAVA_OPTS" -jar <your_jar_file>
例子
% java -Xmx80m -XshowSettings:all -jar HelloWorld.jar
…
VM settings:
Max. Heap Size: 80.00M
Ergonomics Machine Class: server
Using VM: Java HotSpot(TM) 64-Bit Server VM
…
全部描述man java
-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 JAVA_OPTS="-Xmx3g"
无法工作,
JAVA_OPTS= …
不是有效的参数java
JAVA_OPTS="-Xmx3g"
有效,但在您的情况下毫无用处,因为您定义了一个环境变量但没有使用它,例如:
% JAVA_OPTS="-Xmx3g" % echo $JAVA_OPTS -Xmx3g