Skip to main content

Essential Java Startup and JVM Arguments Explained

· 2 min read
Apache Wangye
Software developer and technical writer

This note explains a typical Java startup command used while running load tests on Linux:

java -server \
-XX:+HeapDumpOnOutOfMemoryError \
-Xms512m \
-Xmx512m \
-XX:+UseG1GC \
-XX:MaxGCPauseMillis=250 \
-XX:G1ReservePercent=20 \
-Djava.security.egd=file:/dev/urandom \
-jar xxxx.jar

JVM options must appear before -jar or the main class. Application arguments belong after the JAR name or main class. When diagnosing startup problems, record the exact command, Java version, environment variables, operating-system limits, and container memory limits.

Option reference

  • -server: selects the server compiler and runtime profile. On modern 64-bit JDKs, the server VM is generally the default.
  • -XX:+HeapDumpOnOutOfMemoryError: writes a heap dump when an OutOfMemoryError occurs. Also configure -XX:HeapDumpPath so the output location is predictable and writable.
  • -Xms512m: sets the initial Java heap size to 512 MB.
  • -Xmx512m: sets the maximum Java heap size to 512 MB.
  • -XX:+UseG1GC: selects the G1 garbage collector. G1 is already the default on many current JDK releases.
  • -XX:MaxGCPauseMillis=250: defines a soft pause-time target for G1. It is not a strict maximum.
  • -XX:G1ReservePercent=20: reserves part of the heap to reduce evacuation and promotion failures. Increasing it leaves less space for ordinary allocations.
  • -Djava.security.egd=file:/dev/urandom: sets a Java system property related to the entropy source. Its effect depends on the JDK and operating system, so verify whether it is still needed on your runtime.

Check the active runtime and resolved flags with:

java -version
java -XX:+PrintFlagsFinal -version

For production services, prefer observable and version-appropriate GC logging, for example with unified logging on JDK 9 and later:

-Xlog:gc*,safepoint:file=/var/log/app/gc.log:time,uptime,level,tags:filecount=10,filesize=20M

Do not copy JVM tuning options blindly between applications. Start from measured heap usage, allocation rate, pause requirements, and the resource limits of the deployment environment.

Page views: --

Total views -- · Visitors --