Scrivio Interview library
ConceptFoundations7 min read · updated 12 November 2026

What is Java Flight Recorder, and how do you start a recording on a service that is already running? How do you look at the results?

Java Flight Recorder (JFR) is an event recorder built into the JVM that records what happens inside it, such as garbage collections, allocation samples, lock contention, file and socket I/O and method samples, with low overhead; it has been open source since JDK 11. On a running service we start it with jcmd <pid> JFR.start duration=60s filename=rec.jfr, adding settings=profile for more detail, and at launch with -XX:StartFlightRecording and the same options. We look at the results in JDK Mission Control or with the jfr command line tool, for example jfr summary and jfr print. The default settings aim for about 1 percent overhead; the profile settings record more and cost more.

Why this question is asked

When a Java service misbehaves, we want to know what the JVM and the application were doing over time, not only at one instant like a thread dump. JFR gives exactly that, cheaply enough to run in production, and it is built in, so there is nothing to install. Interviewers ask about it because it has become the standard first tool for performance and diagnostics work on modern JDKs. In this answer, we will see what JFR records and how it stays cheap, start a recording on a running service and at launch, choose between the default and profile settings, and read the results with Mission Control and the jfr tool.

1What JFR Records

JFR is a recorder of events. An event is a small record with a timestamp, a duration where it applies, the thread, often a stack trace, and fields specific to the event type. The JVM emits events for garbage collection phases and pauses, heap statistics, object allocation samples, threads blocked on monitors or parked, socket and file reads and writes, exceptions, class loading, JIT compilation and safepoints. It also samples the stacks of running threads at regular intervals, which gives a CPU profile. Libraries and applications can define their own events too, through the jdk.jfr API.

JFR started as a commercial feature in the Oracle JDK and was open-sourced in JDK 11, and it is also available in later JDK 8 updates. Today it is a standard part of OpenJDK builds.

2How It Stays Cheap

JFR is designed for production. Events are written into thread-local buffers inside the JVM without locking, then moved in batches to global buffers and finally to disk in a compact binary format. Expensive events are sampled or filtered by thresholds instead of being recorded every time: for example, only lock waits longer than 20 ms, or one allocation sample out of many. A settings file controls which events are on and their thresholds, and the default one aims for about 1 percent overhead, which makes continuous recording realistic.

Step throughHow a JFR recording is produced
  1. JVM and application codeemit events: GC, locks, I/O, samples
  2. Thread-local bufferswritten without locks
  3. Global buffersfilled in batches
  4. Repository on diskchunks in the binary .jfr format
  5. Recording filedumped on request, at the end or on exit

5 layers, from the top down. Step through them one at a time.

3Starting a Recording on a Running Service

For a service that is already running, we use jcmd, which sends the command into the JVM through the attach API. No restart and no flags at startup are needed.

Shell
jcmd 4711 JFR.start name=slow duration=60s filename=/tmp/rec.jfr
# Started recording 1. The result will be written to: /tmp/rec.jfr
jcmd 4711 JFR.start name=detail duration=120s settings=profile filename=/tmp/detail.jfr
jcmd 4711 JFR.check # lists running recordings and their state
jcmd 4711 JFR.dump name=detail filename=/tmp/so-far.jfr # write what we have now
jcmd 4711 JFR.stop name=detail # stop early

With duration, the recording stops by itself and writes the file at the end. Without it, the recording runs until we stop it, and JFR.dump lets us take a copy at any point. The file path is written by the target JVM, so in a container it is a path in the application's file system. The settings option selects the configuration: default for continuous use and profile for a short, detailed investigation.

4Starting JFR at Launch

To have JFR running from the start, or continuously, we pass -XX:StartFlightRecording with the same options. A common production pattern is a continuous recording that keeps the last few hours on disk and is written out when needed or when the JVM exits.

Text
# a fixed recording of the first 5 minutes, for example to study startup
java -XX:StartFlightRecording=duration=300s,filename=/tmp/startup.jfr -jar orders.jar
# continuous: keep the last 6 hours or 1 GB, write on exit
java -XX:StartFlightRecording=disk=true,maxage=6h,maxsize=1g,dumponexit=true,filename=/diagnostics/ -jar orders.jar
# later, during an incident:
jcmd 1 JFR.dump filename=/diagnostics/incident.jfr

The continuous recording is like a flight recorder in an aircraft, which is where the name comes from: when something goes wrong, the recent past is already on disk.

5Default Versus Profile Settings

The two built-in settings files trade detail for cost. Default records the essential events with higher thresholds and less frequent sampling, aiming for about 1 percent overhead. Profile lowers thresholds, samples more often and enables more events, such as more allocation detail, for roughly 2 percent overhead or more, depending on the workload.

Built-in JFR settings
defaultprofile
Intended usecontinuous, always onshort investigations
Overhead targetabout 1 percenthigher, often about 2 percent
Method samplingless frequentmore frequent
Lock and I/O thresholdshigher (fewer events)lower (more events)
File size per hoursmallerlarger

We can also copy a settings file and adjust individual events, or create one in Mission Control's template manager, when we need a specific event at a low threshold without turning on everything else.

6Looking at the Results

JDK Mission Control (JMC), a separate free download, opens .jfr files and presents them as views: an automated analysis page that flags likely problems, method profiling as a flame graph or tree, GC pauses over time, lock contention, I/O, allocation by class and by stack, and the raw event browser. It is the easiest way to explore a recording.

The jfr command line tool, included in the JDK, is handy on servers and in scripts. jfr summary shows which events a file contains and how many, jfr print prints events as text or with --json, filtered with --events, and recent JDKs add jfr view with ready-made tables such as hot methods and GC pauses.

Shell
jfr summary /tmp/rec.jfr
# Event Type Count Size (bytes)
# jdk.ExecutionSample 5872 94120
# jdk.GarbageCollection 138 6210
# jdk.JavaMonitorEnter 41 2870
jfr print --events jdk.GarbageCollection /tmp/rec.jfr | head -20
jfr view hot-methods /tmp/rec.jfr # JDK 21 and later; jfr view --help lists the views

A typical first pass is summary to see what was captured, then the GC pause and hot methods views to see whether time goes to collection or to code, then lock and I/O events if threads were waiting rather than computing.

7Follow-up questions

Is it safe to leave JFR on in production all the time?

With the default settings, generally yes, which is why many teams run a continuous recording. The overhead is usually around 1 percent, but measure it on your own service. Remember that recordings can contain sensitive values, such as strings in some events, so store them with care.

How is JFR different from a thread dump?

A thread dump is a single snapshot of all threads at one instant. JFR records events over a period, so it shows how often something happened, how long it took and what led up to it, including GC, I/O and allocation, not only thread stacks.

Can JFR stream events live instead of writing a file?

Yes. Since JDK 14, the JFR event streaming API lets a program subscribe to events as they are recorded, for example to export GC pause times or lock contention to a metrics system.

8Conclusion

In this answer, we saw that JFR is a low-overhead event recorder built into the JVM, open source since JDK 11, that records GC, allocation samples, locks, I/O, method samples and more through lock-free thread-local buffers and thresholds. We started recordings on a running JVM with jcmd JFR.start and at launch with -XX:StartFlightRecording, chose between the default settings, about 1 percent overhead, and the more detailed profile settings, and read the results in JDK Mission Control or with jfr summary, jfr print and jfr view.

What to say in the interviewAbout 100 seconds aloud

Open with

Java Flight Recorder is an event recorder built into the JVM. It records things like GC phases and pauses, allocation samples, threads blocked on locks or parked, socket and file I/O, exceptions, JIT compilation and regular method samples, which give a CPU profile.

Then, if they want more

It's cheap because events go into thread-local buffers without locks and expensive events are sampled or only recorded above a threshold, so the default settings aim for about one percent overhead. It's been open source since JDK 11.

On a running service I don't need to restart anything: jcmd pid JFR.start with a name, a duration like 60 seconds and a filename, and settings=profile if I want more detail for a short investigation, at a somewhat higher cost. JFR.check lists recordings, JFR.dump writes what's recorded so far, and JFR.stop ends it.

At launch I use -XX:StartFlightRecording with the same options, and in production I like a continuous recording on disk with a max age of a few hours, so when something goes wrong the recent past is already there and I just dump it.

To look at results I open the file in JDK Mission Control, which has an automated analysis page, flame graphs, GC, lock and I/O views.

On a server I use the jfr tool: jfr summary to see what's in the file, jfr print with --events to filter, and on recent JDKs jfr view for things like hot methods and GC pauses.

About this answer

Last updated
12 November 2026
Versions it names
Java 11, Java 14, Java 21, Java 8
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "What is Java Flight Recorder, and how do you start a recording on a service that is...": https://scrivio-interview-library.netlify.app/java/jvm-diagnostics/99a62510bb/