Java Flight Recorder (JFR): Your JVM's Black Box
JFR is a profiling and event-collection framework built into the JVM. Unlike traditional profilers that add 10-20% overhead, JFR is designed for production use, typically consuming less than 1% of your CPU.
1. Why JFR is Different
JFR is not an external tool. It is tightly integrated into the JVM's runtime. It records events as they happen (e.g., GC starts, thread sleeps, TLAB allocations) directly into a circular buffer in memory.
2. Capturing a Recording
You can start a recording at any time via the command line:
jcmd <pid> JFR.start duration=60s filename=my_profile.jfr
3. Analysis with JDK Mission Control (JMC)
JFR files are binary. To read them, you use JMC.
- Method Profiling: See where your CPU is actually spending time.
- Latency Analysis: Identify exactly which thread was blocked on which lock for how long.
- Memory Allocation: Track which methods are creating the most garbage, leading to GC pressure.
Summary
JFR provides the ground-truth data you need to solve hard production performance issues. Every senior Java developer should have JFR recordings as their first step in any performance investigation.
