Alex Martian
Alex Martian

Reputation: 3782

Java Flight Recorder (JFR) from command line: [jfr] [ERROR] [1014.291] Repository could not be removed at shutdown

I'm following course on Java Flight Recorder usage java-flight-recorder-monitoring.

I compiled a java code from example (adding class and imports because it did not compile w/out them):

import java.util.ArrayList;
import java.util.List;

class TestFlightRecorder {
public static void main(String[] args) {
    List<Object> items = new ArrayList<>(1);
    try {
        while (true){
            items.add(new Object());
        }
    } catch (OutOfMemoryError e){
        System.out.println(e.getMessage());
    }
    assert items.size() > 0;
    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {
        System.out.println(e.getMessage());
    }
}
}

Then I run as per course:

C:\Program Files\Java\jdk1.8.0_191\bin>java -XX:+UnlockCommercialFeatures -XX:+F lightRecorder -XX:StartFlightRecording=duration=200s,filename=c:\am\out\flight.j fr -cp c:\am\out TestFlightRecorder

Output right after:

Started recording 1. The result will be written to:

C:\AM\out\flight.jfr

Memory usage in Windows task manager of java goes up, then after much more than 200 seconds:

Exception in thread "main" java.lang.OutOfMemoryError: Java heap space at TestFlightRecorder.main(TestFlightRecorder.java:12) [jfr][ERROR][1014.291] Repository could not be removed at shutdown

And resulting flight.jfr have size of 0 bytes. (when I made the same command with simple hello world java class, flight.jfr was created with size 125Kb with 'empty' info inside - that I guess is due to the fact app worked so quickly flight recording had not started yet - and this question is not about that emptiness).

Web search for such error was w/out results. Why error, have I done something incorrectly to make a recording?

Upvotes: 2

Views: 2498

Answers (2)

Kire Haglin
Kire Haglin

Reputation: 7069

Java Flight Recorder writes the dump in a Java shutdown hook when the application ends. If there is not enough memory to produce the dump it will fail.

The error happens because the file is still held by the JVM while the shutdown hook thread tries to remove it.

Upvotes: 2

Alex Martian
Alex Martian

Reputation: 3782

Hinted by comment made by Aaron:

OOMError which likely disrupts the JVM enough that the flightrecorder fails to write

I ran the code with recoding time of 20s, not 200s (in task manager I saw java memory usage grow to max heap of 2Gb in about that time too) and got resulting recording with graphs similar to presented in the course. So I consider current issue solved.

Upvotes: 1

Related Questions