Reputation:
As it is described in many sources I am trying to use java -Xms512m
from the command line in order to set maximum size of heap for java machine to 512 Mb.
But something goes wrong and command line shows the following
And, as I checked directly from the program:
long heapMaxSize = Runtime.getRuntime().maxMemory();
heapMaxSize is equal to 954728448 which is about 1Gb.
Upvotes: 2
Views: 472
Reputation: 14361
This is called a VM parameter, and must be specified when you start your VM (the JVM).
You may specify the maximum heap size as you run your program:
java -Xmx1024m -jar yourJar.jar
Or alternatively, you can set an environment variable on your system JAVA_OPTS
and the JVM will respect your settings as it starts:
JAVA_OPTS="-Xmx1024m"
Regarding your second question, I would refer you to What are Runtime.getRuntime().totalMemory() and freeMemory()? as it clarifies what values are returned by Runtime.getRuntime().maxMemory()
and friends.
Upvotes: 3
Reputation: 44965
-Xmx<size>
: Max Size of the Java Heap (young generation + tenured generation)-Xms<size>
: Initial Size of the Java Heap (young generation + tenured generation)-Xmn<size>
: Size of the young generation Heap spaceThe problem that you face is not related to -Xms
, it is due to the fact that your java
command is incomplete, indeed you need to provide a jar with a main class defined in the META-INF/MANIFEST.MF
or the FQN of the class to launch.
Upvotes: 1