- java.lang.Object
- 
- jdk.internal.event.Event
- 
- jdk.jfr.Event
 
 
- 
 public abstract class Event extends jdk.internal.event.EventBase class for events, to be subclassed in order to define events and their fields.The following example shows how to implement an Eventclass.import jdk.jfr.Event; import jdk.jfr.Description; import jdk.jfr.Label; public class Example { @Label("Hello World") @Description("Helps programmer getting started") static class HelloWorld extends Event { @Label("Message") String message; } public static void main(String... args) { HelloWorld event = new HelloWorld(); event.message = "hello, world!"; event.commit(); } }After an event is allocated and its field members are populated, it can be written to the Flight Recorder system by using the #commit()method.By default, an event is enabled. To disable an event annotate the Eventclass with@Enabled(false).Supported field types are the Java primitives: boolean,char,byte,short,int,long,float, anddouble. Supported reference types are:String,ThreadandClass. Arrays, enums, and other reference types are silently ignored and not included. Fields that are of the supported types can be excluded by using the transient modifier. Static fields, even of the supported types, are not included.Tools can visualize data in a meaningful way when annotations are used (for example, Label,Description, andTimespan). Annotations applied to anEventclass or its fields are included if they are present (indirectly, directly, or associated), have theMetadataDefinitionannotation, and they do not contain enums, arrays, or classes.Gathering data to store in an event can be expensive. The shouldCommit()method can be used to verify whether an event instance would actually be written to the system when theEvent#commit()commitmethod is invoked. IfshouldCommit()returns false, then those operations can be avoided.- Since:
- 9
 
- 
- 
Constructor SummaryConstructors Modifier Constructor Description protectedEvent()Sole constructor, for invocation by subclass constructors, typically implicit.
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description voidbegin()Starts the timing of this event.voidcommit()Writes the field values, time stamp, and event duration to the Flight Recorder system.voidend()Ends the timing of this event.booleanisEnabled()Returnstrueif at least one recording is running, and the enabled setting for this event is set totrue, otherwisefalseis returned.voidset(int index, Object value)Sets a field value.booleanshouldCommit()Returnstrueif the enabled setting for this event is set totrueand if the duration is within the threshold for the event,falseotherwise.
 
- 
- 
- 
Method Detail- 
beginpublic final void begin() Starts the timing of this event.- Overrides:
- beginin class- jdk.internal.event.Event
 
 - 
endpublic final void end() Ends the timing of this event. Theendmethod must be invoked after thebeginmethod.- Overrides:
- endin class- jdk.internal.event.Event
 
 - 
commitpublic final void commit() Writes the field values, time stamp, and event duration to the Flight Recorder system.If the event starts with an invocation of the beginmethod, but does not end with an explicit invocation of theendmethod, then the event ends when thecommitmethod is invoked.- Overrides:
- commitin class- jdk.internal.event.Event
 
 - 
isEnabledpublic final boolean isEnabled() Returnstrueif at least one recording is running, and the enabled setting for this event is set totrue, otherwisefalseis returned.- Overrides:
- isEnabledin class- jdk.internal.event.Event
- Returns:
- trueif event is enabled,- falseotherwise
 
 - 
shouldCommitpublic final boolean shouldCommit() Returnstrueif the enabled setting for this event is set totrueand if the duration is within the threshold for the event,falseotherwise. The threshold is the minimum threshold for all running recordings.- Overrides:
- shouldCommitin class- jdk.internal.event.Event
- Returns:
- trueif the event can be written to the Flight Recorder system,- falseotherwise
 
 - 
setpublic final void set(int index, Object value)Sets a field value.Applicable only if the event is dynamically defined using the EventFactoryclass.The supplied indexcorresponds to the index of theValueDescriptorobject passed to the factory method of theEventFactoryclass.- Overrides:
- setin class- jdk.internal.event.Event
- Parameters:
- index- the index of the field that is passed to- EventFactory#create(String, java.util.List, java.util.List)
- value- value to set, can be- null
- Throws:
- UnsupportedOperationException- if it's not a dynamically generated event
- IndexOutOfBoundsException- if- indexis less than- 0or greater than or equal to the number of fields specified for the event
- See Also:
- EventType.getFields(),- EventFactory
 
 
- 
 
-