'jmap
-finalizerinfo {PROCESS_ID}' command prints the information on objects awaiting
finalization.
Let
me explain with an example.
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.
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.
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
No comments:
Post a Comment