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

0 votes
Answer 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
Community showcase
Published Mar 12, 2019 in Confluence

Confluence Admin Certification now $150 for Community Members

More and more people are building their careers with Atlassian, and we want you to be at the front of this wave! Important Dates Start the Certification Prep Course by 2 April 2019 Take your e...

1,349 views 2 13
Read article

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