Java Flight Recorder (JFR) for Production Troubleshooting
Aug 02, 2025 am 12:53 AMJava Flight Recorder (JFR) is essential for diagnosing production Java issues with minimal overhead. 1. JFR captures critical runtime data including CPU profiling, garbage collection, thread activity, exceptions, I/O, and JVM internals, enabling analysis of latency spikes, memory leaks, deadlocks, and performance degradation. 2. Enable JFR at startup using -XX: FlightRecorder and -XX:StartFlightRecording with options for duration, delay, and settings, or attach dynamically to running JVMs via jcmd JFR.start for on-demand diagnostics. 3. Analyze .jfr files using JDK Mission Control (JMC) for visual insights into hot methods, GC trends, and thread behavior, or use command-line tools like jfr for automated processing. 4. Best practices include enabling JFR by default, using rolling recordings, securing output files, integrating with APM tools, avoiding prolonged profile settings unless needed, and testing on resource-constrained systems. Proactively using JFR ensures issues are captured and analyzed without reproduction, transforming troubleshooting into efficient root-cause discovery.
Java Flight Recorder (JFR) is a powerful diagnostic and profiling tool built into the JDK, especially useful for troubleshooting performance issues in production environments. It collects detailed runtime data with minimal overhead—typically less than 2%—making it safe to use even in live systems.

Here’s how JFR can be effectively used for production troubleshooting:
1. What JFR Captures (and Why It Matters)
JFR records a wide range of low-level and application-level events, including:

- CPU profiling (method-level execution times, hot methods)
- Garbage collection (GC duration, frequency, heap usage, pause times)
- Thread activity (lock contention, blocked threads, thread states)
- Class loading/unloading
- Exception telemetry (frequency of exceptions thrown)
- I/O and network activity (if enabled)
- JVM internal operations (safepoints, code cache, compiler activity)
This data is invaluable when diagnosing:
- Sudden latency spikes
- Memory leaks or high GC pressure
- Deadlocks or thread bottlenecks
- Unexpected application slowdowns
Because JFR runs continuously in the background (when enabled), you can capture a recording after an issue occurs—retroactively analyzing what happened.

2. Enabling JFR in Production
JFR is available in OpenJDK 11 and all Oracle JDKs (with fewer restrictions in commercial versions). To use it in production:
Start your JVM with JFR enabled:
java -XX: FlightRecorder \ -XX:StartFlightRecording=duration=60s,filename=diagnosis.jfr \ -jar myapp.jar
Or, for continuous monitoring:
java -XX: FlightRecorder \ -XX:StartFlightRecording=delay=30s,duration=0s,filename=rolling.jfr,settings=profile \ -jar myapp.jar
Note: Use
settings=profile
for more detailed event profiling (e.g., object allocation, method profiling). The defaultsettings=default
is lighter.
For already-running JVMs (attach dynamically):
Use jcmd
to start a recording without restarting:
jcmd <pid> JFR.start name=web-issue duration=120s filename=/tmp/issue.jfr settings=profile
Later, stop it:
jcmd <pid> JFR.stop name=web-issue
This is ideal when an issue arises unexpectedly.
3. Analyzing JFR Recordings
Once you have a .jfr
file, analyze it using:
JDK Mission Control (JMC)
- Open-source GUI tool designed specifically for JFR analysis.
- Visualize flame graphs, GC trends, thread timelines, and I/O patterns.
- Filter events, inspect stack traces, and identify hot methods.
Alternative: Use command-line or CI tools
- Tools like jfr or JFR-Analyzer allow automated parsing.
- Extract metrics programmatically for integration into monitoring pipelines.
Example: Finding a CPU spike
- Open the JFR file in JMC.
- Go to the “Hot Methods” view.
- Look for methods consuming high CPU (self time or total time).
- Check the stack trace to locate the root cause—e.g., inefficient loop, regex backtracking, or serialization bottleneck.
4. Best Practices for Production Use
- ? Enable JFR by default on production JVMs (low overhead, high value).
- ? Use continuous rolling recordings (e.g., 1-hour buffers) to capture recent history.
- ? Secure
.jfr
files—recordings may contain sensitive data (e.g., method parameters, stack traces). - ? Combine with APM tools (like Datadog, New Relic) for correlation.
- ? Avoid long-duration recordings with
settings=profile
unless necessary—higher overhead. - ? Don’t enable JFR on very resource-constrained systems without testing.
Bottom Line
JFR is one of the most effective tools for diagnosing production Java issues with minimal impact. When enabled proactively, it turns reactive firefighting into proactive root-cause analysis. You don’t need to reproduce the problem in staging—JFR likely already captured it.
Set it up once, and it pays dividends every time something goes wrong.
Basically: If you’re not using JFR in production, you’re flying blind.
The above is the detailed content of Java Flight Recorder (JFR) for Production Troubleshooting. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

The settings.json file is located in the user-level or workspace-level path and is used to customize VSCode settings. 1. User-level path: Windows is C:\Users\\AppData\Roaming\Code\User\settings.json, macOS is /Users//Library/ApplicationSupport/Code/User/settings.json, Linux is /home//.config/Code/User/settings.json; 2. Workspace-level path: .vscode/settings in the project root directory

To correctly handle JDBC transactions, you must first turn off the automatic commit mode, then perform multiple operations, and finally commit or rollback according to the results; 1. Call conn.setAutoCommit(false) to start the transaction; 2. Execute multiple SQL operations, such as INSERT and UPDATE; 3. Call conn.commit() if all operations are successful, and call conn.rollback() if an exception occurs to ensure data consistency; at the same time, try-with-resources should be used to manage resources, properly handle exceptions and close connections to avoid connection leakage; in addition, it is recommended to use connection pools and set save points to achieve partial rollback, and keep transactions as short as possible to improve performance.

itertools.combinations is used to generate all non-repetitive combinations (order irrelevant) that selects a specified number of elements from the iterable object. Its usage includes: 1. Select 2 element combinations from the list, such as ('A','B'), ('A','C'), etc., to avoid repeated order; 2. Take 3 character combinations of strings, such as "abc" and "abd", which are suitable for subsequence generation; 3. Find the combinations where the sum of two numbers is equal to the target value, such as 1 5=6, simplify the double loop logic; the difference between combinations and arrangement lies in whether the order is important, combinations regard AB and BA as the same, while permutations are regarded as different;

DependencyInjection(DI)isadesignpatternwhereobjectsreceivedependenciesexternally,promotingloosecouplingandeasiertestingthroughconstructor,setter,orfieldinjection.2.SpringFrameworkusesannotationslike@Component,@Service,and@AutowiredwithJava-basedconfi

fixture is a function used to provide preset environment or data for tests. 1. Use the @pytest.fixture decorator to define fixture; 2. Inject fixture in parameter form in the test function; 3. Execute setup before yield, and then teardown; 4. Control scope through scope parameters, such as function, module, etc.; 5. Place the shared fixture in conftest.py to achieve cross-file sharing, thereby improving the maintainability and reusability of tests.

JavaFlightRecorder(JFR)andJavaMissionControl(JMC)providedeep,low-overheadinsightsintoJavaapplicationperformance.1.JFRcollectsruntimedatalikeGCbehavior,threadactivity,CPUusage,andcustomeventswithlessthan2%overhead,writingittoa.jfrfile.2.EnableJFRatsta

Laravel's error and exception handling mechanism is based on the PHP exception system and Symfony component, and is managed uniformly by the App\Exceptions\Handler class. 1. Record exceptions through the report() method, such as integrating Sentry and other monitoring services; 2. Convert exceptions into HTTP responses through the render() method, supporting custom JSON or page jumps; 3. You can create custom exception classes such as PaymentFailedException and define their response format; 4. Automatically handle verification exception ValidationException, and manually adjust the error response structure; 5. Decide whether to display details based on the APP_DEBUG configuration.

TheJVMenablesJava’s"writeonce,runanywhere"capabilitybyexecutingbytecodethroughfourmaincomponents:1.TheClassLoaderSubsystemloads,links,andinitializes.classfilesusingbootstrap,extension,andapplicationclassloaders,ensuringsecureandlazyclassloa
