Skip to content

Instantly share code, notes, and snippets.

@jbachorik
Created September 6, 2020 17:02
@JfrPeriodicEventHandler
// register a periodic JFR event and assing its handler to this method; the periodicity is defined in the Event itself via 'jdk.jfr.Period' annotation
public static void handleSimplePeriodic(SimplePeriodicEvent event) {
// the handler code will be called periodically by the JFR infrastructure
if (event.shouldCommit()) {
// if the event type is enabled and there is an ongoing recording set up the valued and commit the event
event.setValue(10);
event.commit();
}
}
@JfrBlock(SimpleEvent.class)
// create a block containing JFR event calls; all the event types enumerated in the annotation will be automatically registered
public static void emitEvent(long bytesRead) {
// instantiate the event
SimpleEvent event = new SimpleEvent();
if (event.shouldCommit()) {
// if the event type is enabled and there is an ongoing recording set up the valued and commit the event
event.setValue(bytesRead);
event.commit();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment