Java Tools Tutorials - Herong's Tutorial Notes - Version 5.31, by Dr. Herong Yang
Taking Thread Dump to See Thread Stack Traces
This section provides a tutorial example on how to take a thread dump with Java VisualVM to get a snapshot of all threads with their execution statuses and stack traces.
What Is Thread Dump? A thread dump is a snapshot of all threads with their execution point when the dump was taken and their stack traces. Thread dump helps you to understand what's going on in the JVM in terms of thread executions. For example, if your Java application is running very slow, you can take thread dump to find out what your application threads are doing.
Java VisualVM can help you to create a thread dump file at any time.
1. Start Java VisualVM and connect to the running JVM of LongSleep.java.
2. Click on the Threads tab. The thread screen is displayed.
3. Click on the "Thread Dump" button. A copy of the thread dump is created and displayed.
4. Right-mouse click on "[threaddump]..." under "LongSleep..." in the Application panel. Then select "Save As..." to save the thread dump to a file called thread_dump.tdump. A thread dump is a text file. You can open it with any text editor.
5. Open the thread dump file in a text editor. You will a list of threads with their statuses and execution stack traces.
Full thread dump Java HotSpot(TM) Client VM (25.0-b70 mixed mode): "JMX server connection timeout 12" daemon prio=6 tid=0x03f02c00 nid=0x2e7c in Object.wait() [0x03cbf000] java.lang.Thread.State: TIMED_WAITING (on object monitor) at java.lang.Object.wait(Native Method) - waiting on <0x2906b568> (a [I) at com.sun.jmx.remote.internal.ServerCommunicatorAdmin$Timeout.run (ServerCommunicatorAdmin.java:168) - locked <0x2906b568> (a [I) at java.lang.Thread.run(Thread.java:744) Locked ownable synchronizers: - None "RMI Scheduler(0)" daemon prio=6 tid=0x03f06000 nid=0x12fc waiting on condition [0x046cf000] java.lang.Thread.State: TIMED_WAITING (parking) at sun.misc.Unsafe.park(Native Method) - parking to wait for <0x28fec4e8> (a java.util.concurrent.locks. AbstractQueuedSynchronizer$ConditionObject) at java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.... at java.util.concurrent.locks.AbstractQueuedSynchronizer$Conditi... at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQ... at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQ... at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExe... at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolE... at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPool... at java.lang.Thread.run(Thread.java:744) ... "main" prio=6 tid=0x0115bc00 nid=0x1378 waiting on condition [0x0110f000] java.lang.Thread.State: TIMED_WAITING (sleeping) at java.lang.Thread.sleep(Native Method) at LongSleep.main(LongSleep.java:10) Locked ownable synchronizers: - None ...
Last update: 2015.
Table of Contents