DEV Community

Lucien Boix
Lucien Boix

Posted on

9

How to do a thread dump on a pod running a Java app ?

If your Java app is struggling with busy threads pilling up, there's nothing better to have a look at the state of those threads and see what was their last action before they hung.

Here is a simple TODO to achieve that if your app is running inside a Kubernetes pod (we will assume that this one only run 1 container).

Open your terminal and tail the logs of your pod :

kubectl get po |grep "YOUR_APP"
kubectl logs -f POD_NAME
Enter fullscreen mode Exit fullscreen mode

Open a new tab of your terminal, and launch the thread dump :

# connect to your pod's container
kubectl exec -it POD_NAME -- sh
# find the PID of your Java process (it should be 1)
ps aux
# force a thread dump to stdout (do not worry : this will not kill the application)
kill -3 YOUR_PID
Enter fullscreen mode Exit fullscreen mode

Go back in your first tab and analyse the results.

For example it allowed me one time to quickly find out that I had a key locked in my Redis instance. What else did you discover through them ? Please share your experiences in the comments.

Take care and have a great day !

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay