Class JfrEnhancementsExamples

java.lang.Object
net.jrodolfo.java_evolution.java25.jfr_enhancements.JfrEnhancementsExamples

public class JfrEnhancementsExamples extends Object
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.

  • Constructor Details

    • JfrEnhancementsExamples

      public JfrEnhancementsExamples()
  • Method Details

    • problem

      public String problem()
      Explains the problem that JFR helps solve.
      Returns:
      a short problem statement
    • features

      public String features()
      Names the Java 25 JFR areas represented by this learning module.
      Returns:
      feature summary
    • cpuTimeProfilingCaveat

      public String cpuTimeProfilingCaveat()
      Explains why CPU-time profiling remains explanatory in this repository.
      Returns:
      a short compatibility caveat
    • cooperativeSamplingCaveat

      public String 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 .jfr recording, 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