Java Flight Recorder (JFR) — Continuous Production Profiling Built Into the JVM
Fast recall
Quick revision
Core answer
-XX:StartFlightRecording=... at JVM launch or on-demand with jcmd JFR.start . Analyze the resulting .jfr file in JVM Mission Control (JMC) for correlated timeline views, or query the events programmatically via the jdk.jfr.consumer API. JFR is the right tool for after-the-fact diagnosis — when monitoring shows a latency spike, JFR tells you what was happening inside the JVM at that moment.Whether you know JFR is production-grade and continuous (not just an on-demand profiler) and can articulate when JFR is better than async-profiler
Treating JFR as a heavy-weight tool to be enabled only when investigating — it is designed for always-on use and provides far more value continuously than reactively
Explain the Method Profiling Sample event mechanism (default 10ms sampling) and how to write a custom JFR event in application code for business-level observability
Interview-ready guide
Interview answer
Java Flight Recorder is a low-overhead event recorder built directly into the HotSpot JVM. It is open-source in Java 11 and later, and it is the closest thing Java has to a flight recorder for production incidents.
What makes JFR special:
- Built into the JVM — no agent overhead, no safepoint bias, access to internal events external tools cannot see
- Designed for continuous recording with under 1-2% overhead — always-on in production
- Captures over 150 event types: GC, CPU samples, threads, locks, allocation, JIT, class loading, I/O
Production setup:
- Add
-XX:StartFlightRecording=maxage=24h,maxsize=2g,filename=/var/recordings/app.jfr,dumponexit=true,settings=profileat JVM launch - Recording rolls automatically; oldest events are evicted; on-disk file capped at 2GB
- On any incident, dump a snapshot with
jcmdJFR.dump name=continuous filename=/tmp/incident.jfr
Analysis with JMC (JVM Mission Control):
- Free GUI from Oracle/Adoptium
- Automated Analysis tab runs heuristics and identifies likely problems
- Timeline view shows GC, threads, locks, I/O all correlated against time — scrub to a latency spike and see the cause immediately
Custom events for business observability:
- Extend
jdk.jfr.Eventto define application events with custom fields - Emit them around HTTP requests, database queries, business operations
- Now you can correlate slow orders with GC pauses or lock contention happening at the same moment
JFR vs async-profiler:
- JFR: continuous, correlated, always-on
- async-profiler: focused flame graphs for one specific question
- Use both — JFR continuously, async-profiler for deep dives
Common misconception:
- JFR is no longer a heavy-weight tool — modern JFR is designed for always-on production use
- Netflix, Datadog, and similar shops run continuous JFR on every JVM
In an interview, the differentiator is mentioning custom JFR events — most candidates know JFR exists; few know they can extend it for business-level observability.
Java Flight Recorder (JFR) — Continuous Production Profiling Built Into the JVM
Direct Answer
Java Flight Recorder (JFR) is a low-overhead event recorder built directly into the HotSpot JVM. It captures GC events, CPU samples, thread states, lock contention, allocation patterns, JIT compilation, class loading, and I/O — all in a single recording with under 1% overhead. Open-sourced in Java 11, JFR is designed to run continuously in production. Start it via -XX:StartFlightRecording=... at JVM launch or on-demand with jcmd <pid> JFR.start. Analyze the resulting .jfr file in JVM Mission Control (JMC) for correlated timeline views, or query the events programmatically via the jdk.jfr.consumer API. JFR is the right tool for after-the-fact diagnosis — when monitoring shows a latency spike, JFR tells you what was happening inside the JVM at that moment.
Common Mistakes & Pitfalls
Treating JFR as a heavy-weight tool to be enabled only when investigating — it is designed for always-on use and provides far more value continuously than reactively
Check your understanding
Answer these without looking back at the article.
- What's the difference between JFR and a sampling profiler like async-profiler?
- How do you write a custom JFR event for application-level observability?
- How do you analyze a JFR recording programmatically without JMC?
- What is the overhead of running JFR continuously in production?
Related interview prep categories
2Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.