Flags
-XX:StartFlightRecording starts JFR at JVM launch. It can write to disk,
limit file size or age, dump on exit, and use different settings profiles.
Flag details
- -XX:StartFlightRecording=filename=recordings/app-%p.jfr
- Starts JFR immediately and writes the recording to a file.
%pexpands to the JVM process ID. - dumponexit=true
- Dumps the recording when the JVM exits, useful for short-lived jobs or graceful shutdown analysis.
- maxsize=256m
- Limits how much recording data is kept on disk. Use this to avoid filling local storage during continuous recording.
- settings=profile
- Uses a more detailed JFR event configuration than the default. It is useful during targeted profiling and may add more overhead than a light continuous recording.
- duration=10m
- Stops the recording automatically after ten minutes, which is helpful for controlled load tests.
When to use it
Use this for always-available incident context, performance baselines, latency analysis, allocation profiling, lock contention, and CPU investigations without attaching a tool after the process is already sick.
Java version support
Java Flight Recorder became an open feature in Java 11. The -XX:StartFlightRecording
launch option is the normal way to start a recording at JVM startup on modern JDKs.
Related JEPs
Examples
java -XX:StartFlightRecording=filename=recordings/app-%p.jfr,dumponexit=true,maxsize=256m \
-jar app.jar
Use this for always-available incident context with bounded disk usage.
java -XX:StartFlightRecording=name=profile,settings=profile,duration=10m,filename=profile.jfr \
-jar app.jar
Use this during a controlled profiling window, such as a load test.
Verify
Open the resulting .jfr in JDK Mission Control and check CPU, allocation, GC, lock, and thread views.