Java 11: Flight Recorder
Java 11 made Flight Recorder free to use.
Download JMC(Java Mission Control) from here https://jdk.java.net/jmc/ to Analyse the Flight Recorder output.
Create this file which will generate java.lang.OutOfMemoryError: Java heap space error.
package com.nuwan.java11;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
public class JavaFlightRecorder {
private static BlockingQueue<byte[]> queue=new LinkedBlockingQueue<>();
public static void main(String[] args) {
Runnable producer = () -> {
while (true) {
queue.offer( new byte[1*1024*1024]);
try {
TimeUnit.MILLISECONDS.sleep(10);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
};
Runnable consumer = () -> {
while (true){
try {
queue.take();
TimeUnit.MILLISECONDS.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
};
new Thread(producer,"Producer Thread").start();
new Thread(consumer,"Consumer Thread").start();
}
}After compiling the file run as below.
java -XX:StartFlightRecording=duration=30s,settings=profile,filename=leak.jfr JavaFlightRecorderAs per this example java file recorder file will be created in the same place where java class is located. To analyze the file you can use JMC which we already downloaded. Use below reference link for to find how to analyze via JMC.
Get Nuwan Zen’s stories in your inbox
Join Medium for free to get updates from this writer.
Ref: https://mkyong.com/java/java-11-java-flight-recorder/
JCMD for Running Java process
We can use jcmd to monitor running java processors.
Let’s see what are the running processors at the moment:
jcmdThis command will list down all the java processors running. Now let’s start JFR for the application we need.
jcmd 19073 JFR.start duration=30s settings=profile filename=nuwan-jfr.jfrFile we be generated and you can analyse it by openning it through JMC.
My Other Blogs:
My Other Blogs:







