The flag Xmx specifies the maximum memory allocation pool for a Java Virtual Machine (JVM), while Xms specifies the initial memory allocation pool. This means that your JVM will be started with Xms amount of memory and will be able to use a maximum of Xmx amount of memory. For example, starting a JVM like below will start it with 256 MB of memory and will allow the process to use up to 2048 MB ...
The -Xmx option changes the maximum Heap Space for the VM. java -Xmx1024m means that the VM can allocate a maximum of 1024 MB. In layman terms this means that the application can use a maximum of 1024MB of memory.
-Xms and -Xmx simply specifies the range in which the JVM can operate and resize the heap. If -Xms and -Xmx are the same value, then the JVM's heap size will stay constant at that value. It's typically best to just set -Xmx and let the JVM find the best heap size, unless there's a specific reason why you need to give the JVM a big heap at JVM ...
The speed tradeoffs between various settings of -Xms and -Xmx depend on the application and system that you run your Java application on. It also depends on your JVM and other garbage collection parameters you use.
In the oracle documentation I found: -Xmx size Specifies the maximum size (in bytes) of the memory allocation pool in bytes ... The default value is chosen at runtime based on system configuration. What does system configuration mean?
The -Xmx parameter belongs to the (nonstandard) JVM options, and--being an option--needs to be listed before -jar (or at least before file.jar). The JVM will not recognize an -Xmx argument passed to the main function as proposed in other answers.
According to the Garbage Collector Ergonomics page, the maximum heap size is: Smaller of 1/4th of the physical memory or 1GB. Before J2SE 5.0, the default maximum heap size was 64MB. By using the -Xmx switch can be used to change the maximum heap size. See the java - the Java application launcher documentation for usage details.
You can't do it using environment variables directly. You need to use the set of "non standard" options that are passed to the java command. Run: java -X for details. The options you're looking for are -Xmx and -Xms (this is "initial" heap size, so probably what you're looking for.) Some products like Ant or Tomcat might come with a batch script that looks for the JAVA_OPTS environment ...
What the difference between -Xms4096m -Xmx2048M -XX:MaxPermSize=712M I am getting confused of this two -Xmx2048M and -XX:MaxPermSize=712M and will happen if I use -Xmx2048M or -Xmx2048m
In JDK 8, The default maximum heap size is 1/4th of the physical memory or 1GB And it can be overridden using the -Xmx switch: You can override this default using the -Xmx command-line option. ...