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 !

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read more →

Top comments (0)

Image of Datadog

The Essential Toolkit for Front-end Developers

Take a user-centric approach to front-end monitoring that evolves alongside increasingly complex frameworks and single-page applications.

Get The Kit