Performance
performance3JfrConcepts
- Path
- pkg19performance/performance3JfrConcepts.java
- Package
- pkg19performance
- Study order
- 3
- Run
- Single-file source launch
- Command
- java pkg19performance/performance3JfrConcepts.java
There is no in-browser runner. This is the file from the curriculum, unchanged.
1package pkg19performance;2 3/*4 * performance3JfrConcepts.java5 * ------------------------------6 * Java Flight Recorder (JFR): low-overhead production profiling built into the JDK.7 *8 * DEFINITION:9 * JFR records JVM and application events (CPU, locks, GC, I/O, custom) with10 * minimal overhead. Analyze recordings in JDK Mission Control (JMC) or jfr print.11 *12 * KEY POINTS:13 * - Start: -XX:StartFlightRecording=... or jcmd <pid> JFR.start14 * - Events: jdk.CPULoad, jdk.GarbageCollection, jdk.ThreadStart, custom @Name events15 * - jfr print recording.jfr — CLI summary16 * - Prefer JFR over ad-hoc logging for performance investigations.17 */18public class performance3JfrConcepts {19 20 public static void main(String[] args) throws InterruptedException {21 System.out.println("JFR is built into the JDK (no extra install).");22 System.out.println("\nStart a 10s recording from CLI:");23 System.out.println(" java -XX:StartFlightRecording=duration=10s,filename=demo.jfr performance3JfrConcepts.java");24 System.out.println("\nOr attach to running process:");25 System.out.println(" jcmd <pid> JFR.start name=demo settings=profile duration=30s filename=demo.jfr");26 System.out.println(" jfr print --events jdk.GarbageCollection demo.jfr");27 28 // Simulate some work while a recording might run29 long sum = 0;30 for (int i = 0; i < 10_000_000; i++) sum += i;31 System.out.println("\nComputed sum (work sample): " + sum);32 }33}