Class JfrEnhancementsExamples
java.lang.Object
net.jrodolfo.java_evolution.java25.jfr_enhancements.JfrEnhancementsExamples
Demonstrates Java Flight Recorder (JFR) method timing and tracing introduced
in Java 25.
Java 25 also added JFR CPU-time profiling and cooperative sampling. Those are documented here as runtime caveats because CPU-time profiling is experimental and platform-dependent, and cooperative sampling is a profiling-quality improvement rather than a behavior that a small unit test can prove faithfully.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordSummary of method events observed in a JFR recording. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionExplains why cooperative sampling remains explanatory in this repository.Explains why CPU-time profiling remains explanatory in this repository.features()Names the Java 25 JFR areas represented by this learning module.problem()Explains the problem that JFR helps solve.recordMethodTimingAndTracing(Path recordingFile) Records JFR method timing and tracing events for a selected method.static longtracedWork(int value) Performs a small amount of repeatable work for the JFR recording.
-
Constructor Details
-
JfrEnhancementsExamples
public JfrEnhancementsExamples()
-
-
Method Details
-
problem
Explains the problem that JFR helps solve.- Returns:
- a short problem statement
-
features
Names the Java 25 JFR areas represented by this learning module.- Returns:
- feature summary
-
cpuTimeProfilingCaveat
Explains why CPU-time profiling remains explanatory in this repository.- Returns:
- a short compatibility caveat
-
cooperativeSamplingCaveat
Explains why cooperative sampling remains explanatory in this repository.- Returns:
- a short testing caveat
-
recordMethodTimingAndTracing
public JfrEnhancementsExamples.JfrMethodObservation recordMethodTimingAndTracing(Path recordingFile) throws IOException Records JFR method timing and tracing events for a selected method.The method writes a real
.jfrrecording, reads it back with the JFR consumer API, and returns the observed event counts. The target method is deliberately narrow so the recording stays deterministic enough for executable documentation.- Parameters:
recordingFile- the file that will receive the JFR recording- Returns:
- the method-timing and method-tracing events observed in the recording
- Throws:
IOException- when the recording cannot be written or read
-
tracedWork
public static long tracedWork(int value) Performs a small amount of repeatable work for the JFR recording.The implementation is intentionally simple. The lesson is how JFR records a selected method, not how to microbenchmark Java code.
- Parameters:
value- input value- Returns:
- deterministic computed value
-