chapter ten

10 Investigating deadlocks with thread dumps

 

This chapter covers

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

In this chapter, we discuss using thread dumps for analyzing the thread execution at a given moment in time. Often, we use thread dumps in situations where the application becomes unresponsive, such as in the case of a deadlock. A deadlock is a situation where multiple threads pause their execution waiting for each other to fulfill a given condition. If a hypothetical thread A ends up waiting for thread B to do something and thread B waits for thread A, neither of them 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 such an issue to find its root cause and eventually solve the problem.

Because with a deadlock the process might completely freeze, you usually can’t use sampling or profiling (instrumentation) anymore as 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 that indicates the details of the thread is named 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 easier grasp thread dumps

10.3 Summary