Default parameters of XMS and XMX in JVM

+6 votes

Can someone explain the purpose of xms and xmx parameters? Also, what are the default values these parameters during JVM startup?

Announcement! Career Guide 2019 is out now. Explore careers to become a Big Data Developer or Architect!

Jun 1, 2018 in Java by 93.lynn
• 1,550 points
52,990 views

11 answers to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
+2 votes

-xmx and -xms are the parameters used to adjust the heap size.

-Xms: It is used for setting the initial and minimum heap size. It is recommended to set the minimum heap size equivalent to the maximum heap size in order to minimize the garbage collection.

-Xmx: It is used for setting the maximum heap size. The performance will decrease if the max heap value is set lower than the amount of live data. It will force frequent garbage collections in order to free up space.

So, you can say that the JVM will start working with with -Xms amount of memory and further it will be able to use a maximum of -Xmx amount of memory. For example,

java -Xms256m -Xmx2048m

This means, JVM will startup with 256 MB of memory and will allow the process to use up to 2048 MB of memory.

By default, there is no value set for xms, and for xmx its 256MB. You can specify it in multiple formats like kilobytes, megabytes, etc.

-Xmx1024k 

-Xmx512m 

-Xmx8g

answered Jun 1, 2018 by v.liyyah
• 1,290 points
+1 vote

Run this code to see all the options:

java -X

answered Nov 13, 2018 by anonymous
+2 votes
You can go through this blog to better understand XMS and XMX in jvm
https://alvinalexander.com/blog/post/java/java-xmx-xms-memory-heap-size-control
answered Nov 13, 2018 by Nabarupa
+2 votes

The flag Xmx specifies the maximum memory allocation pool for a Java virtual machine (JVM), while Xms specifies the initial memory allocation pool.

The Xms flag has no default value, and Xmx typically has a default value of 256 MB. A common use for these flags is when you encounter a java.lang.OutOfMemoryError.

answered Nov 13, 2018 by Jino
• 5,520 points
+2 votes

You use these Java command-line parameters to help control the RAM use of application:

  •  -Xmx to specify the maximum heap size
  •  -Xms to specify the initial Java heap size
answered Nov 13, 2018 by Murali
0 votes
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
answered Nov 13, 2018 by Maverick
• 10,040 points
0 votes
starting a JVM like below will start it with 256 MB of memory and will allow the process to use up to 2048 MB of memory:

java -Xms256m -Xmx2048m

The memory flag can also be specified in multiple sizes, such as kilobytes, megabytes, and so on.

-Xmx1024k
-Xmx512m
-Xmx8g
answered Nov 13, 2018 by Hannah
• 14,080 points
0 votes
The -xms option is used to set the initial and minimum heap size in Java.

The -xmx option is used to set the final and maximum heap size in Java.
answered Nov 27, 2018 by Shuvodip Ghosh
0 votes

The -Xmx option and -Xms option in combination are used to limit the heap size in Java. 

The Java heap can never grow larger than -Xmx. Also, the -Xms value can be used as “minimum heap size” to set a fixed heap size by setting -Xms = -Xmx.

answered Nov 27, 2018 by Stiphany
0 votes

You can see all the options by running java -X command:

C:\Users\omkar>java -X

    -Xbatch           disable background compilation
    -Xbootclasspath/a:<directories and zip/jar files separated by ;>
                      append to end of bootstrap class path
    -Xcheck:jni       perform additional checks for JNI functions
    -Xcomp            forces compilation of methods on first invocation
    -Xdebug           provided for backward compatibility
    -Xdiag            show additional diagnostic messages
    -Xfuture          enable strictest checks, anticipating future default
    -Xint             interpreted mode execution only
    -Xinternalversion
                      displays more detailed JVM version information than the
                      -version option
    -Xloggc:<file>    log GC status to a file with time stamps
    -Xmixed           mixed mode execution (default)
    -Xmn<size>        sets the initial and maximum size (in bytes) of the heap
                      for the young generation (nursery)
    -Xms<size>        set initial Java heap size
    -Xmx<size>        set maximum Java heap size
    -Xnoclassgc       disable class garbage collection
    -Xrs              reduce use of OS signals by Java/VM (see documentation)
    -Xshare:auto      use shared class data if possible (default)
    -Xshare:off       do not attempt to use shared class data
    -Xshare:on        require using shared class data, otherwise fail.
    -XshowSettings    show all settings and continue
    -XshowSettings:all
                      show all settings and continue
    -XshowSettings:locale
                      show all locale related settings and continue
    -XshowSettings:properties
                      show all property settings and continue
    -XshowSettings:vm show all vm related settings and continue
    -Xss<size>        set java thread stack size
    -Xverify          sets the mode of the bytecode verifier
    --add-reads <module>=<target-module>(,<target-module>)*
                      updates <module> to read <target-module>, regardless
                      of module declaration.
                      <target-module> can be ALL-UNNAMED to read all unnamed
                      modules.
    --add-exports <module>/<package>=<target-module>(,<target-module>)*
                      updates <module> to export <package> to <target-module>,
                      regardless of module declaration.
                      <target-module> can be ALL-UNNAMED to export to all
                      unnamed modules.
    --add-opens <module>/<package>=<target-module>(,<target-module>)*
                      updates <module> to open <package> to
                      <target-module>, regardless of module declaration.
    --illegal-access=<value>
                      permit or deny access to members of types in named modules
                      by code in unnamed modules.
                      <value> is one of "deny", "permit", "warn", or "debug"
                      This option will be removed in a future release.
    --limit-modules <module name>[,<module name>...]
                      limit the universe of observable modules
    --patch-module <module>=<file>(;<file>)*
                      override or augment a module with classes and resources
                      in JAR files or directories.
    --disable-@files  disable further argument file expansion

These extra options are subject to change without notice.
answered Nov 27, 2018 by Omkar
• 66,990 points
0 votes
Hi I cannot connect why?
answered Mar 23 by anonymous
Can you please tell something more about the error you are facing? Explain the error that you are getting, so that we can help you with a solution.

Related Questions In Java

0 votes
2 answers

What is the use of toString method in Java and how can I use it ?

Whenever you require to explore the constructor ...READ MORE

answered Aug 23, 2018 in Java by Daisy
• 8,040 points
218 views
0 votes
1 answer

Why there is the need of getters and setters in java

In Java getters and setters are completely ...READ MORE

answered Jun 26, 2018 in Java by scarlett
• 1,280 points
65 views
+1 vote
1 answer

What are the types of memory in JVM?

The different types of Memory in JVM ...READ MORE

answered Mar 7 in Java by Priyaj
• 56,140 points
84 views
+1 vote
3 answers

What is the syntax to declare and initialize an array in java?

You can use this method: String[] strs = ...READ MORE

answered Jul 25, 2018 in Java by samarth295
• 2,190 points
145 views
0 votes
3 answers

Does Java support Default Parameters?

You can try this with method overloading. void ...READ MORE

answered Sep 21, 2018 in Java by Sushmita
• 6,840 points
129 views
0 votes
1 answer

Is it possible to create a memory leak with Java

Here's a good way to create a memory ...READ MORE

answered May 30, 2018 in Java by parth295
• 4,600 points
64 views
0 votes
1 answer

java.lang.OutOfMemoryError: GC overhead limit exceeded Error

This simply means that for some reason ...READ MORE

answered May 31, 2018 in Java by misc.edu04
• 1,380 points
768 views
0 votes
1 answer

Java Security: Illegal key size or default parameters

Starting from Java 9 or 8u151, you ...READ MORE

answered Aug 23, 2018 in Java by parth295
• 4,600 points
750 views
0 votes
1 answer

Behavior of Integer Wrapper class and == operator

Well, this is happening because of the ...READ MORE

answered Jun 6, 2018 in Java by v.liyyah
• 1,290 points
87 views
0 votes
1 answer

NoClassDefFoundError in Java

Can’t tell you the exact reason as ...READ MORE

answered May 25, 2018 in Java by v.liyyah
• 1,290 points
86 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.