javacodex.com
Java Examples
Java Examples
memu home questions

Using jstack to detect a deadlock

jstack is a utility that returns a complete dump of the various threads running in an app, which you can then use to pinpoint the problem.

In this example the hung process id is PID 10509:

$ jstack 10509
2013-09-04 15:37:45
Full thread dump Java HotSpot(TM) Client VM (23.25-b01 mixed mode):

"Attach Listener" daemon prio=10 tid=0xb6ad5000 nid=0x2926 runnable [0x00000000]
   java.lang.Thread.State: RUNNABLE

"DestroyJavaVM" prio=10 tid=0xb6a06000 nid=0x290e waiting on condition [0x00000000]
   java.lang.Thread.State: RUNNABLE

"Thread-1" prio=10 tid=0xb6ad3800 nid=0x2917 waiting for monitor entry [0xa005a000]
   java.lang.Thread.State: BLOCKED (on object monitor)
	at Deadlock$2.run(Deadlock.java:33)
	- waiting to lock <0xa09caaa0> (a java.lang.String)
	- locked <0xa09caac8> (a java.lang.String)

"Thread-0" prio=10 tid=0xb6ad2800 nid=0x2916 waiting for monitor entry [0xa00ab000]
   java.lang.Thread.State: BLOCKED (on object monitor)
	at Deadlock$1.run(Deadlock.java:17)
	- waiting to lock <0xa09caac8> (a java.lang.String)
	- locked <0xa09caaa0> (a java.lang.String)

"Service Thread" daemon prio=10 tid=0xb6ac3000 nid=0x2914 runnable [0x00000000]
   java.lang.Thread.State: RUNNABLE

"C1 CompilerThread0" daemon prio=10 tid=0xb6ac1400 nid=0x2913 waiting on condition 
[0x00000000]
   java.lang.Thread.State: RUNNABLE

"Signal Dispatcher" daemon prio=10 tid=0xb6abf800 nid=0x2912 runnable [0x00000000]
   java.lang.Thread.State: RUNNABLE

"Finalizer" daemon prio=10 tid=0xb6a83800 nid=0x2911 in Object.wait() [0xa05ad000]
   java.lang.Thread.State: WAITING (on object monitor)
	at java.lang.Object.wait(Native Method)
	- waiting on <0xa0985698> (a java.lang.ref.ReferenceQueue$Lock)
	at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:135)
	- locked <0xa0985698> (a java.lang.ref.ReferenceQueue$Lock)
	at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:151)
	at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:189)

"Reference Handler" daemon prio=10 tid=0xb6a81c00 nid=0x2910 in Object.wait() [0xa05fe000]
   java.lang.Thread.State: WAITING (on object monitor)
	at java.lang.Object.wait(Native Method)
	- waiting on <0xa0985270> (a java.lang.ref.Reference$Lock)
	at java.lang.Object.wait(Object.java:503)
	at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:133)
	- locked <0xa0985270> (a java.lang.ref.Reference$Lock)

"VM Thread" prio=10 tid=0xb6a7c400 nid=0x290f runnable 

"VM Periodic Task Thread" prio=10 tid=0xb6ac5800 nid=0x2915 waiting on condition 

JNI global references: 114


Found one Java-level deadlock:
=============================
"Thread-1":
  waiting to lock monitor 0x09391190 (object 0xa09caaa0, a java.lang.String),
  which is held by "Thread-0"
"Thread-0":
  waiting to lock monitor 0x093905d8 (object 0xa09caac8, a java.lang.String),
  which is held by "Thread-1"

Java stack information for the threads listed above:
===================================================
"Thread-1":
	at Deadlock$2.run(Deadlock.java:33)
	- waiting to lock <0xa09caaa0> (a java.lang.String)
	- locked <0xa09caac8> (a java.lang.String)
"Thread-0":
	at Deadlock$1.run(Deadlock.java:17)
	- waiting to lock <0xa09caac8> (a java.lang.String)
	- locked <0xa09caaa0> (a java.lang.String)

Found 1 deadlock.

Questions answered by this page:

The jstack Utility Detecting Java Thread Deadlocks with jstack Deadlock Detection in Java How to investigate thread deadlocks in Java Applications




Contact: javacodex@yahoo.com