Posts

Showing posts from March 18, 2011

Setting Java Heap Size

Two JVM options are often used to tune JVM heap size: -Xmx for maximum heap size, and -Xms for initial heap size. Here are some common mistakes I have seen when using them: Missing m, M, g or G at the end (they are case insensitive). For example, java -Xmx128 BigApp java.lang.OutOfMemoryError: Java heap space The correct command should be: java -Xmx128m BigApp . To be precise, -Xmx128 is a valid setting for very small apps, like HelloWorld. But in real life, I guess you really mean -Xmx128m Extra space in JVM options, or incorrectly use =. For example, java -Xmx 128m BigApp Invalid maximum heap size: -Xmx Could not create the Java virtual machine. java -Xmx=512m HelloWorld Invalid maximum heap size: -Xmx=512m Could not create the Java virtual machine. The correct command should be java -Xmx128m BigApp , with no whitespace nor =. -X options are different than -Dkey=value system properties, where = is used. Only setting -Xms JVM option and its value is greater t...