← Back

JVM Flag Recipes

Practical launch recipes for common JVM scenarios in 2026. Start here when you know the operational goal, then open a recipe for the flags, tradeoffs, and command examples.

These recipes favor modern HotSpot ergonomics: set the few flags that express a real requirement, observe with GC logs or JFR, and tune from evidence.

Default Production Service

Baseline heap sizing and GC logging for normal server processes on a current JDK.

-Xms-Xmx-Xlog:gc*

Container or Kubernetes Service

Size heap from cgroup limits and inspect what the JVM detects inside the container.

-XX:MaxRAMPercentage-XX:ActiveProcessorCount

Low-Latency API

Use ZGC when short pauses matter more than squeezing out every last point of throughput.

-XX:+UseZGC-Xmx

Throughput-Heavy Batch Job

Favor total completion time for ETL, indexing, reporting, and compiler-style workloads.

-XX:+UseParallelGC-Xms-Xmx

Predictable G1 Pauses

Stay with G1 and give the collector an explicit pause-time target to optimize toward.

-XX:+UseG1GC-XX:MaxGCPauseMillis

Memory-Constrained Service

Reduce unused heap slack when process footprint matters more than peak throughput.

-XX:MaxHeapFreeRatio-XX:MinHeapFreeRatio

Compact Object Headers

Reduce per-object heap overhead for object-dense Java 25 workloads.

-XX:+UseCompactObjectHeaders

Class Data Sharing

Improve startup and memory footprint by reusing archived class metadata.

-Xshare:on-XX:ArchiveClassesAtExit

Many Duplicate Strings

Reduce heap pressure in workloads with repeated identifiers, JSON fields, and log values.

-XX:+UseStringDeduplication-XX:+UseG1GC

Crash and OOM Forensics

Collect heap dumps and JVM fatal-error files when production failures happen.

-XX:+HeapDumpOnOutOfMemoryError-XX:ErrorFile

Continuous Profiling with JFR

Start a bounded Java Flight Recorder recording with low operational friction.

-XX:StartFlightRecording

Native Memory Investigation

Explain RSS beyond Java heap: metaspace, thread stacks, direct buffers, and JVM internals.

-XX:NativeMemoryTracking-XX:+PrintNMTStatistics

Better Linux Profiling Stacks

Improve frame-pointer based stack traces for perf, async-profiler, and eBPF tooling.

-XX:+PreserveFramePointer

Virtual Threads and Structured Concurrency

Scale blocking I/O with virtual threads and keep related subtasks bounded by a scope.

--enable-preview-Djdk.virtualThreadScheduler.parallelism-Djdk.virtualThreadScheduler.maxPoolSize-Djdk.traceVirtualThreadLocals

Stable Runtime Defaults

Pin encoding, timezone, and locale so logs and data pipelines behave consistently.

-Dfile.encoding-Duser.timezone

Module Access Workaround

Use explicit module opens as a temporary bridge for reflective legacy libraries.

--add-opens--add-exports

TLS and Module Security

Configure truststores, keystores, TLS policy, and narrow module-access exceptions.

-Djavax.net.ssl.trustStore-Djdk.tls.disabledAlgorithms--add-opens

Print JVM Ergonomics

Show selected heap, GC, and VM settings at startup for support and diagnostics.

-XX:+PrintCommandLineFlags-XshowSettings:vm