Via
java -Xmx3072m <your_class_name>
ou
java -Xmx3072m -jar <your_jar_file>
ou
JAVA_OPTS="-Xmx3G"
java "$JAVA_OPTS" -jar <your_jar_file>
Exemplo
% 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
…
tudo descrito em 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"
Não funciona,
JAVA_OPTS= …
não é um parâmetro válido parajava
-
JAVA_OPTS="-Xmx3g"
Funciona, mas inútil no seu caso, porque você define uma variável de ambiente sem usá-la, por exemplo:
% JAVA_OPTS="-Xmx3g" % echo $JAVA_OPTS -Xmx3g