Thursday 16 August 2018

jmp: -finalizerinfo: Get information on objects awaiting finalization

'jmap -finalizerinfo {PROCESS_ID}' command prints the information on objects awaiting finalization.

Let me explain with an example.

HelloWorld.java
import java.util.Date;

public class HelloWorld {
 public static void main(String args[]) throws Exception {
  Thread t1 = new Thread() {
   public void run() {
    int count = 0;
    while (true) {
     count++;

     for(int i =0; i< 100; i++){
      Employee emp = new Employee();
      emp.id = count + " : "+ i;
      emp.name = "name " + emp.id;
     }

     try {
      Thread.sleep(1000);
     } catch (Exception e) {

     }
    }
   }
  };

  System.out.println("Application started at : " + new Date());
  t1.start();
 }

 public static class Employee {
  private String id;
  private String name;
 }
}


Compile and run HelloWorld application.

Open another command prompt (or) terminal and execute jcmd command.
C:\>jcmd
18612
15960 HelloWorld
21308 sun.tools.jcmd.JCmd


As you see the output of jcmd command, HelloWorld application is running with process id 15960.

Execute the command 'jmap -finalizerinfo 15960 > finalizeInfo.txt', it copies information on objects awaiting finalization to finalizeInfo.txt file.

Open finalizeInfo.txt file, you can able to see below kind of messages.
Attaching to process ID 15960, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.171-b11
Number of objects pending for finalization: 0




Previous                                                 Next                                                 Home

No comments:

Post a Comment