How to import lib for JMX and Java mission Control?

458 views Asked by At

Two questions I am having are:

  1. How to Import lib for jmx(i can't import it)?

  2. Can we access Java Mission Control using Code? (like I can see the visualisation of my problem but I want to fetch it into my IDE using code), is it possible?

1

There are 1 answers

3
Kire Haglin On BEST ANSWER

If you are using Oracle JDK 9+ or OpenJDK 11+, you can access the data in a JFR file using the Flight Recorder API.

For example, to print all the events:

import jdk.jfr.consumer.*;

try (RecordingFile r = new RecordingFile(Path.of("recording.jfr"))) {
 while (r.hasMoreEvents()) {
   System.out.println(r.readEvent());
 }
}

For more information about the API: https://docs.oracle.com/en/java/javase/11/docs/api/jdk.jfr/jdk/jfr/consumer/package-summary.html