Video in progress
What do the -Xms and -Xmx parameters set?
-Xms is the initial heap size when the JVM starts, and -Xmx is the maximum size the heap can grow to. For example, -Xms512m -Xmx2g.
📖 Answer
java -Xms1g -Xmx1g -jar order-service.jar
With -Xms the JVM reserves that much memory at the start. The heap never exceeds -Xmx: if it needs more but there is no room, you get OutOfMemoryError: Java heap space.
If you don't set them, the JVM calculates them itself: the max heap is usually 1/4 of the available physical memory (or the container limit).
On servers -Xms and -Xmx are often set equal: no time is spent growing and shrinking the heap, the memory is reserved up front, and an unexpected "the OS didn't give memory" case shows up right at the start.
One catch: -Xmx is only the heap limit. The JVM's total memory is larger: Metaspace, thread stacks, the JIT code cache and direct buffers take room too.
Sign up to mark studied questions and save your progress.