Wednesday 8 August 2018

jcmd: GC.heap_dump: Create heap dump

jcmd command provide 'GC.heap_dump' command, it generates java heap dump in HPROF format.

Syntax
jcmd {PROCESS_ID} GC.heap_dump filename=Myheapdump

Follow below step-by-stpe procedure to work with the example.

Step 1: Create HelloWorld.java file with below content.

HelloWorld.java
public class HelloWorld{
 public static void main(String args[])throws Exception{
  Thread t1 = new Thread(){
   public void run(){
    while(true){
     try{
      Thread.sleep(5000);
     }catch(Exception e){
   
     }
    }
   }
  };
  
  t1.start();
 }
}

Compile and run HelloWorld.java application.

Step 2: Use jcmd command to generate heap dump.

Open command prompt and execute jcmd command.

C:\>jcmd
1792 sun.tools.jconsole.JConsole
18144 sun.tools.jcmd.JCmd
13220
17924 HelloWorld

As you see above output, HelloWorld application is running with process id 17924.


Execute the command 'jcmd 17924 help' to get list of all the available commands to the process id 17924.


As you see above image, GC.heap_dump command is available to the process id 17924.

Execute the statement ‘jcmd 17924 GC.heap_dump filename=myHeapDump’ to copy the heap dump to the file myHeapDump.

C:\>jcmd 17924 GC.heap_dump filename=myHeapDump
17924:
Heap dump file created


Previous                                                 Next                                                 Home

No comments:

Post a Comment