RSS

Variation on a theme: which Java thread consumes the most of your CPU?

28 Aug

Tomasz Nurkiewicz wrote a nice blog entry (“Which Java thread consumes my CPU?“) in which he shows a simple method that relies on standard GNU/Linux command-line tools to gather information about the Java threads that keep your CPU very busy.

I wondered whether it would be possible to make it slightly simpler by removing some dependencies and regular expressions and came up with the following Bash shell script:

I think it can be made even simpler and with less dependencies.

Feel free to accept this as a challenge and enlighten me😉

PS: According to Oracle’s jstack web page

This utility is unsupported and may or may not be available in future versions of the J2SE SDK. jstack is not currently available on Windows platforms or on the Linux Itanium platform.

Apparently jstack is still going strong as of 2012, at least on an up-to-date Ubuntu GNU/Linux system, but who knows what awaits us in the future, especially if it is controlled by Oracle😉

 
3 Comments

Posted by on August 28, 2012 in java, Linux, Programlama

 

Tags: , , , ,

3 responses to “Variation on a theme: which Java thread consumes the most of your CPU?

  1. Ali Utku Selen

    August 28, 2012 at 16:27

    pssst… use VisualVM.

     
  2. Emre Sevinc

    August 28, 2012 at 16:36

    And stay away from the joys of the command line which was the main point of this exercise ?😉

    (Not that I don’t like VisualVM and other members of the family, though)

     
  3. Marek

    November 8, 2013 at 00:46

    I prefer oneliners – no installation on any server.

    jstack -l 25343 | egrep -A2 “`ps -T -C java -otid,pcpu| sort -rnk2 | head -n10 | awk ‘{printf “|=0x%x “, $1,$2}’| cut -c2-`”

    just put the PID of the java process you want to check for threads from the top 10 hogs.

     

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: