Java Reference
In-Depth Information
How It Works
JStack allows you to see all the stack traces that the current running threads have.
JStack will also try to find deadlocks (circular dependencies of locks) that might be
stalling your system. JStack will not find other problems such as livelock (when a
thread is always spinning, such as with something like while(true) ), or starvation
(when a thread cannot execute because it is too low of a priority or there are too many
threads competing for resources), but it will help you understand what each of the
threads in your program is doing.
Deadlocks happen because one thread is waiting for a resource that another thread
has, and the second thread is waiting for a resource that the first thread has. In this situ-
ation, neither thread can continue because both are waiting for each other to release the
resource that each one owns. Deadlocks don't only happen between two threads, but
can also involve a “string” of threads so that Thread A is waiting for Thread B is wait-
ing for Thread C is waiting for Thread D is waiting for the original Thread A. It is im-
portant to understand the dump to find the culprit resource.
In this recipe's example, Thread-0 wants to acquire the lock named
0x00000000eab716b8 ; it's described in the thread dump as “waiting for ownable
synchronizer.” Thread-0 cannot acquire the lock because it is held by the main
thread. The main thread, on the other hand, wants to acquire the lock 0x00000000e-
ab716e8 (notice that they are different; the first lock ends in b8 , while the second
ends in e8 ), which is held by Thread-0 . This is a textbook definition of a deadlock
on which each thread is forever waiting for each other to release the lock the other
thread has.
Aside from deadlock, looking at thread dumps gives you an idea about what your
program is doing in realtime. Especially in multithreaded systems, using thread dumps
will help clarify where a thread is sleeping or what condition it is waiting for.
Note JStack is usually lightweight enough to be run in a live system, so if you need
to troubleshoot live problems, you can safely use JStack.
Search WWH ::




Custom Search