Is there any way to see more information on who initiated a Java thread?

I recently had a single Java thread out of my confluence instance run away from me. Using top -H, I could see that this thread was consistently running CPU usage up to 99.9% while all the others appeared normal.

Is there any way I can map this thread to a single user or to a single IP address or to a single task. Perhaps next time this happens I can ask the user to stop what they are doing and log out rather than restart the entire Confluence service for everyone.

1 answer

1 accepted

For the googlers,

I found this script elsewhere and it did the trick:

#!/bin/bash
PID=$(top -n1 | grep -m1 java | perl -pe 's/\e\[?.*?[\@-~] ?//g' | cut -f1 -d' ')
echo The PID of the Confluence process is $PID
TID=$(top -n1 -H | grep -m1 java | perl -pe 's/\e\[?.*?[\@-~] ?//g' | cut -f1 -d' ')
echo The PPID of the highest CPU consuming Java thread is $TID
NID=$(printf "%x" $TID)
echo The hex value of the highest CPU consuming Java thread is $NID
if [[ $PID -gt 0 && "$NID" != "0" ]]; then
        sudo /usr/java/jdk1.6.0_20/bin/jstack $PID | grep -A500 $NID | grep -m1 "^$" -B 500
fi;

echo -n "OS thread count is: "
ps -eL | grep java | wc -l

echo -n "Open file count is: "
sudo /usr/sbin/lsof | grep java | wc -l

echo -n "Total established connection count is "
sudo /usr/sbin/lsof -i | grep java | grep -i established | wc -l

echo -n "HTTPS incoming connection count is: "
sudo /usr/sbin/lsof -i | grep java | grep -i established | grep :https | wc -l

echo -n "Total other (outgoing) connection count is: "
sudo /usr/sbin/lsof -i | grep java | grep -i established | grep -v ":https" | wc -l

echo -n "Database (outgoing) connection count is: "
sudo /usr/sbin/lsof -i | grep java | grep -i established | grep "dbServer" | wc -l

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Posted Jul 10, 2018 in Confluence

We want to see the templates you've created in Confluence!

Hi Community, Jessica here from the Confluence Product Marketing team!  July’s community challenge is all about sharing pictures  — and as an extension of our first post on what ...

849 views 23 12
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you