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
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
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 !
Top comments (0)