March 2019
Intermediate to advanced
242 pages
6h 21m
English
As a developer, you can also create your own custom events using the JFR API and view and analyze them using MC. Here's an example; let's define a custom event:
class MyEvent extends Event {
@Label("EventMessage")
String message;
}
Now let's modify the AThread class to use events, instead of printing to console:
class AThread implements Runnable { String name = "default"; private Random numGenerator = new Random(); private ArrayList<Double> list = new ArrayList<Double>(1000000); AThread(String name) { this.name = name; } public void run() { MyEvent event; for (int i = 0; i < 1000000; i++) { list.add(numGenerator.nextDouble()); event = new MyEvent(); event.message = "Allocated : " + name + "[" + i + "]"; event.commit(); ...Read now
Unlock full access