モジュール jdk.jfr
パッケージ jdk.jfr

クラスEventFactory

java.lang.Object
jdk.jfr.EventFactory

public final class EventFactory extends Object
実行時にイベントを定義するためのクラスです。

フィールド・レイアウトがわかっている場合は、コンパイル時にイベントを定義することを強くお薦めします。したがって、Java Virtual Machine (JVM)はコードを最適化できます。Flight Recorderが非アクティブな場合、またはこのイベントの有効な設定がfalseに設定されている場合は、すべてのインストゥルメンテーションが削除される可能性があります。

コンパイル時にイベントを定義するには、Eventを参照してください。

次の例は、動的Eventクラスを実装する方法を示しています。

List<ValueDescriptor> fields = new ArrayList<>();
List<AnnotationElement> messageAnnotations = Collections.singletonList(new AnnotationElement(Label.class, "Message"));
fields.add(new ValueDescriptor(String.class, "message", messageAnnotations));
List<AnnotationElement> numberAnnotations = Collections.singletonList(new AnnotationElement(Label.class, "Number"));
fields.add(new ValueDescriptor(int.class, "number", numberAnnotations));

String[] category = { "Example", "Getting Started" };
List<AnnotationElement> eventAnnotations = new ArrayList<>();
eventAnnotations.add(new AnnotationElement(Name.class, "com.example.HelloWorld"));
eventAnnotations.add(new AnnotationElement(Label.class, "Hello World"));
eventAnnotations.add(new AnnotationElement(Description.class, "Helps programmer getting started"));
eventAnnotations.add(new AnnotationElement(Category.class, category));

EventFactory f = EventFactory.create(eventAnnotations, fields);

Event event = f.newEvent();
event.set(0, "hello, world!");
event.set(1, 4711);
event.commit();

導入されたバージョン:
9