20 Haziran 2023 Salı

RecordingStream Sınıfı - Flight Recorder - Java 11 İle Geliyor

Giriş
Şu satırı dahil ederiz
import jdk.jfr.consumer.RecordingStream;
Örnek
Şöyle yaparız
import jdk.jfr.consumer.RecordingStream;

public static void main(String[] args) {
  try (var rs = new RecordingStream()) {
    rs.onEvent("jdk.GarbageCollection", event ->
      System.out.format("Garbage collection: %s, duration: %dns%n", event.getEndTime(), event.getDuration())
  );

    rs.startAsync();
    Thread.sleep(60_000);
  } catch (InterruptedException e) {
    e.printStackTrace();
  }
}
Açıklaması şöyle
In this example, we create a RecordingStream, define an event handler for garbage collection events, start the stream asynchronously, and keep the application alive for 60 seconds to observe the events.

Hiç yorum yok:

Yorum Gönder