‘jcmd’
is a command line tool provided by Java, used to send diagnostic command
requests to the JVM.
Open
command prompt and run ‘jcmd’.
C:\>jcmd 13828 sun.tools.jcmd.JCmd 5012 HelloWorld 8456
As
you see the output of jcmd, it shows the process id and the application name.
Application name
|
Process Id
|
HelloWorld
|
5012
|
sun.tools.jcmd.JCmd
|
13828
|
Use
the command ‘jcmd HelloWorld help’ to get list of commands available for
HelloWorld application.
C:\>jcmd HelloWorld help 5012: The following commands are available: JFR.stop JFR.start JFR.dump JFR.check VM.native_memory VM.check_commercial_features VM.unlock_commercial_features ManagementAgent.stop ManagementAgent.start_local ManagementAgent.start GC.rotate_log Thread.print GC.class_stats GC.class_histogram GC.heap_dump GC.run_finalization GC.run VM.uptime VM.flags VM.system_properties VM.command_line VM.version Help
As
you see there are multiple commands are available to the program ‘HelloWorld’.
You can get the help of these command by using following syntax.
Syntax
jcmd
{APPLICATION_NAME} help {COMMAND}
Example
jcmd HelloWorld help Thread.print
jcmd HelloWorld help Thread.print
C:\>jcmd HelloWorld help Thread.print 5012: Thread.print Print all threads with stacktraces. Impact: Medium: Depends on the number of threads. Permission: java.lang.management.ManagementPermission(monitor) Syntax : Thread.print [options] Options: (options must be specified using the <key> or <key>=<value> syntax) -l : [optional] print java.util.concurrent locks (BOOLEAN, false)
Get the thread dump using
jcmd
Use
the below command to get the thread dump.
jcmd
PID Thread.print > thread.dump
Example
jcmd
5012 Thread.print > thread.dump
Above
command prints all the threads with stack traces associated with process id
5012, to thread.dump file.
In my case, thread.dump file contains below data.
thread.dump
5012: 2018-07-22 19:29:18 Full thread dump Java HotSpot(TM) 64-Bit Server VM (25.171-b11 mixed mode): "DestroyJavaVM" #11 prio=5 os_prio=0 tid=0x0000000004be2800 nid=0x37f4 waiting on condition [0x0000000000000000] java.lang.Thread.State: RUNNABLE "Thread-0" #10 prio=5 os_prio=0 tid=0x000000001fccc000 nid=0x4690 waiting on condition [0x000000002034f000] java.lang.Thread.State: TIMED_WAITING (sleeping) at java.lang.Thread.sleep(Native Method) at HelloWorld$1.run(HelloWorld.java:9) "Service Thread" #9 daemon prio=9 os_prio=0 tid=0x000000001e34d800 nid=0x32f0 runnable [0x0000000000000000] java.lang.Thread.State: RUNNABLE "C1 CompilerThread2" #8 daemon prio=9 os_prio=2 tid=0x000000001e2f5000 nid=0x4f54 waiting on condition [0x0000000000000000] java.lang.Thread.State: RUNNABLE "C2 CompilerThread1" #7 daemon prio=9 os_prio=2 tid=0x000000001e2f0000 nid=0x1f08 waiting on condition [0x0000000000000000] java.lang.Thread.State: RUNNABLE "C2 CompilerThread0" #6 daemon prio=9 os_prio=2 tid=0x000000001e2ed000 nid=0x41f8 waiting on condition [0x0000000000000000] java.lang.Thread.State: RUNNABLE "Attach Listener" #5 daemon prio=5 os_prio=2 tid=0x000000001e2f9800 nid=0x2ab8 waiting on condition [0x0000000000000000] java.lang.Thread.State: RUNNABLE "Signal Dispatcher" #4 daemon prio=9 os_prio=2 tid=0x000000001e2f8800 nid=0x3570 runnable [0x0000000000000000] java.lang.Thread.State: RUNNABLE "Finalizer" #3 daemon prio=8 os_prio=1 tid=0x0000000004cdc800 nid=0x3aec in Object.wait() [0x000000001f64f000] java.lang.Thread.State: WAITING (on object monitor) at java.lang.Object.wait(Native Method) - waiting on <0x000000076b508ed0> (a java.lang.ref.ReferenceQueue$Lock) at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:143) - locked <0x000000076b508ed0> (a java.lang.ref.ReferenceQueue$Lock) at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:164) at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:212) "Reference Handler" #2 daemon prio=10 os_prio=2 tid=0x0000000004cd3000 nid=0x243c in Object.wait() [0x000000001f54f000] java.lang.Thread.State: WAITING (on object monitor) at java.lang.Object.wait(Native Method) - waiting on <0x000000076b506bf8> (a java.lang.ref.Reference$Lock) at java.lang.Object.wait(Object.java:502) at java.lang.ref.Reference.tryHandlePending(Reference.java:191) - locked <0x000000076b506bf8> (a java.lang.ref.Reference$Lock) at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:153) "VM Thread" os_prio=2 tid=0x000000001e2b7800 nid=0x39c runnable "GC task thread#0 (ParallelGC)" os_prio=0 tid=0x0000000004bf8000 nid=0x160c runnable "GC task thread#1 (ParallelGC)" os_prio=0 tid=0x0000000004bfa000 nid=0x4808 runnable "GC task thread#2 (ParallelGC)" os_prio=0 tid=0x0000000004bfb800 nid=0x4dcc runnable "GC task thread#3 (ParallelGC)" os_prio=0 tid=0x0000000004bfd000 nid=0x5cc runnable "VM Periodic Task Thread" os_prio=2 tid=0x000000001e34e000 nid=0x2318 waiting on condition JNI global references: 4
No comments:
Post a Comment