Menu

Your Service Has Stopped Responding and You Have Never Taken a Thread Dump
📰

Your Service Has Stopped Responding and You Have Never Taken a Thread Dump

DEV Community: java·Asael Shinder·1 day ago
#t9fH5G4M
#devtojava#devto#dev#thread#process
Reading 0:00
15s threshold

The service is still running. The process is there, the memory looks normal, and the CPU is almost idle. But every request hangs until it times out, and the logs stopped twenty minutes ago without a single error. Someone suggests restarting it. Before you do, spend one minute capturing what every thread inside it is doing right now. That snapshot is called a thread dump, and once you have read one, you will never want to restart a stuck service blind again.

On the Java virtual machine there are three common ways to take one. Run jstack followed by the process id. Or run jcmd with the process id and Thread.print. Or send the process a quit signal with kill -3, which makes the JVM write the dump to its own standard output, so in a container it appears in the logs. Take three dumps about ten seconds apart. A thread that is in the same place in all three is stuck, not busy.

Each thread appears with a name, a state and a stack trace. The state tells you a lot.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.