1

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
enter image description here

And, as I checked directly from the program: long heapMaxSize = Runtime.getRuntime().maxMemory(); heapMaxSize is equal to 954728448 which is about 1Gb.

  • 2
    Your image is huge. Please consider retaking the screen shot and uploading a smaller version. – erip Jun 17 '16 at 16:35

2 Answers2

3

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.

Community
  • 1
  • 1
SnakeDoc
  • 13,611
  • 17
  • 65
  • 97
1
  • -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 space

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

Nicolas Filotto
  • 43,537
  • 11
  • 94
  • 122