How are @TransitionFrom and @TransitionTo supposed to be used

Viewed 89

The Java Flight Recorder API contains two annotations TransitionFrom and TransitionTo but the documentation is very light on how they should be used.

How are they supposed to be used? I assume they go on fields of events. Should they be boolean or thread fields? When should the fields be set to which values?

1 Answers

The purpose of @TransitionTo and @TransitionFrom is to hint to a graphical user interface like JDK Mission Control that there is a transition from thread A to thread B.

The GUI can then visualize it as transition arrows:

Transition Graph

If you commit the event in thread A, you would create a thread field and annotate it with @TransitionTo and assign thread B to it.

@Name("com.organization.product.Notification")
@Label("Notification")
public class Notification extends jdk.jfr.Event {
   @TransitionTo
   @Label ("Receiver");
   Thread receiver;
}

If it is more convenient to commit the event in thread B, you would create a field annotated with @TransitionFrom and assign it with thread A instead.

@Name("com.organization.product.Notification")
@Label("Notification")
public class Notification extends jdk.jfr.Event {
   @TransitionFrom
   @Label ("Notifier");
   Thread notifier;
}
Related