15 Exclude Fields from Being Persisted with the transient Keyword
You can exclude fields from being persisted with the transient keyword. The example ExcludeFieldsSample.java
demonstrates this.
import jdk.jfr.Event;
import jdk.jfr.Label;
import jdk.jfr.Name;
public class ExcludeFieldsSample {
@Name("com.oracle.Message")
@Label("Message")
static class Message extends Event {
String messageA;
transient String messageB;
String messageC;
}
public static void main(String... args) {
Message event = new Message();
event.messageA = "hello";
event.messageB = "world"; // will not be persisted.
event.messageC = "!";
event.commit();
}
}
Run ExcludeFieldsSample
with the following commands:
java -XX:StartFlightRecording:filename=excludefieldssample.jfr ExcludeFieldsSample.java
jfr print --events Message excludefieldssample.jfr
The last command prints output similar to the following:
com.oracle.Message {
startTime = 23:41:15.425
messageA = "hello"
messageC = "!"
...
}