What is Java Flight Recorder (JFR) in Java?

Java Flight Recorder (JFR) is a powerful profiling and diagnostics tool integrated into the Java Virtual Machine (JVM). It allows developers and system administrators to collect and analyze performance data of Java applications in a production environment with minimal overhead. JFR is particularly useful for identifying bottlenecks, memory leaks, and other performance-related issues.

JFR logs a variety of events and metrics, such as CPU usage, memory allocation, thread activity, and garbage collection details, to give comprehensive insights into runtime behavior. It allows users to capture data continuously or on-demand, enabling fine-grained analysis without significant intrusion on application performance.

To use JFR, you can enable it by using JVM flags while starting your Java application, like so:

java -XX:StartFlightRecording=duration=1m,filename=myrecording.jfr -jar myapp.jar

This command starts a flight recording for one minute and saves the output to a file named "myrecording.jfr". You can later analyze this recording using tools like Java Mission Control (JMC).


Java Flight Recorder JFR Java profiling JVM diagnostics Java performance monitoring