How to Profile Java Applications in Docker Containers with JFR

Transcript:

Hi friends! In this video, I will show you how to profile Java applications in Docker containers using Java Flight Recorder. Java Flight Recorder (JFR) is a low-overhead profiling and diagnostic tool built into the OpenJDK, so you don't have to install it manually. We can profile the application right from the start, attach to a running application, or observe it in JDK Mission Control.

First, let's look at how to start a JFR recording at application startup. You can take any application—I'm using Spring PetClinic. The Dockerfile includes Liberica JDK Lite and minimalistic Alpaquita Linux. The most important option to enable JFR is ‘StartFlightRecording’, where you can set parameters like duration and filename. After building and running the container, you can retrieve the recording file from the ‘tmp’ directory using docker cp. The recorded data can be analyzed in JDK Mission Control, an open-source tool.

Now, let's see how to attach to a running container and profile it. Instead of enabling JFR at startup, we can use the ‘jcmd’ tool, which is part of the JDK. However, production images usually contain only the JRE, not the full JDK. To solve this, we use ephemeral containers—temporary containers that include the JDK and attach to the running application. By running an ephemeral container with ‘pid=container’, we can use ‘jcmd’ to start a JFR recording. After profiling, we retrieve the file with docker cp without restarting the main container.

Lastly, if you want to monitor a running application in real time, JDK Mission Control allows remote profiling. We modify the Dockerfile to enable remote JVM connections using JMX-related options like ‘jmxremote.port’ and ‘jmxremote.rmi.port’. After rebuilding and running the container with these options, we connect to the JVM in Liberica Mission Control. This lets us observe real-time performance metrics.

In this video, we covered how to profile Java applications in containers using Java Flight Recorder. In a future video, we will explore profiling containerized Java apps with Async Profiler, another low-overhead profiler. Don't forget to like this video, subscribe to our channel, and see you next time!

Summary

This video explains how to profile Java applications in Docker containers using Java Flight Recorder (JFR), a built-in OpenJDK tool. It covers three profiling methods: enabling JFR at application startup, attaching to a running container using an ephemeral container with `jcmd`, and monitoring real-time performance with JDK Mission Control via remote JVM connections. Step-by-step instructions are provided for configuring Dockerfiles, retrieving profiling data, and analyzing application performance.

About Catherine

Java developer passionate about Spring Boot. Writer. Developer Advocate at BellSoft

Social Media

Videos
card image
Dec 12, 2025
Will AI Replace Developers? A Vibe Coding Reality Check 2025

Can AI replace software engineers? ChatGPT, Copilot, and LLM-powered vibe coding tools promise to automate development—but after testing them against 17 years of production experience, the answer is more nuanced than the hype suggests. Full project generation produces over-engineered code that's hard to refactor. AI assistants excel at boilerplate but fail at business logic. MCP servers solve hallucination problems but create context overload. Meanwhile, DevOps automation actually works. This breakdown separates AI capabilities from marketing promises—essential for teams integrating LLMs and copilots without compromising code quality or architectural decisions.

Videos
card image
Dec 12, 2025
JRush | Container Essentials: Fast Builds, Secure Images, Zero Vulnerabilities

Web-conference for Java developers focused on hands-on strategies for building high-performance containers, eliminating CVEs, and detecting security issues before production.

Further watching

Videos
card image
Dec 30, 2025
Java in 2025: LTS Release, AI on JVM, Framework Modernization

Java in 2025 isn't about headline features, it's about how production systems changed under the hood. While release notes focus on individual JEPs, the real story is how the platform, frameworks, and tooling evolved to improve stability, performance, and long-term maintainability. In this video, we look at Java from a production perspective. What does Java 25 LTS mean for teams planning to upgrade? How are memory efficiency, startup time, and observability getting better? Why do changes like Scoped Values and AOT optimizations matter beyond benchmarks? We also cover the broader ecosystem: Spring Boot 4 and Framework 7, AI on the JVM with Spring AI and LangChain4j, Kotlin's growing role in backend systems, and tooling updates that make upgrades easier. Finally, we touch on container hardening and why runtime and supply-chain decisions matter just as much as language features.

Videos
card image
Dec 24, 2025
I Solved Advent of Code 2025 in Kotlin: Here's How It Went

Every year, Advent of Code spawns thousands of solutions — but few engineers step back to see the bigger picture. This is a complete walkthrough of all 12 days from 2025, focused on engineering patterns rather than puzzle statements. We cover scalable techniques: interval math without brute force, dynamic programming, graph algorithms (JGraphT), geometry with Java AWT Polygon, and optimization problems that need constraint solvers like ojAlgo. You'll see how Java and Kotlin handle real constraints, how visualizations validate assumptions, and when to reach for libraries instead of writing everything from scratch. If you love puzzles, programming—or both—and maybe want to learn how to solve them on the JVM, this is for you.

Videos
card image
Dec 18, 2025
Java 26 Preview: New JEPs and What They Mean for You

Java 26 is the next feature release that brings features for enhanced performance, security, and developer experience. This video discusses the upcoming JDK 26 release, highlighting ten JEPs including JEP 500. JEP 500 focuses on preparing developers for future restrictions on mutating final fields in Java, emphasizing their role in maintaining immutable state. This is crucial for robust programming and understanding the nuances of mutable vs immutable data, especially concerning an immutable class in java. We also touch upon the broader implications for functional programming in Java.