10 Investigating deadlocks with thread dumps

 

This chapter covers

  • Getting thread dumps using a profiler
  • Getting thread dumps using the command line
  • Reading thread dumps to investigate issues

In this chapter, we’ll discuss using thread dumps to analyze thread execution at a given moment in time. Often, we use thread dumps in situations in which the application becomes unresponsive, such as in the case of a deadlock. A deadlock occurs when multiple threads pause their execution and wait for each other to fulfill a given condition. If hypothetical thread A waits for thread B to do something, and thread B waits for thread A, neither can continue their execution. In such a case, the app, or at least a part of it, will freeze. We need to know how to analyze this issue to find its root cause and eventually solve the problem.

Because a deadlock may cause a process to completely freeze, you usually can’t use sampling or profiling (instrumentation), like we did in chapter 9. Instead, you can get a statistic of all the threads and their states for a given JVM process. This statistic is called a thread dump.

10.1 Getting a thread dump

10.1.1 Getting a thread dump using a profiler

10.1.2 Generating a thread dump from the command line

10.2 Reading thread dumps

10.2.1 Reading plain-text thread dumps

10.2.2 Using tools to better grasp thread dumps

Summary