3 Replies Latest reply on Jan 8, 2009 5:32 PM by Peter Johnson

    Identifying the thread that is eating up my CPU

    Matthieu Labour Newbie

      Hi

      I need a little bit of help to get started

      I use jboss4.2.2 with Jboss Messaging 1.4.0 SP3

      My application is eating up 100% CPU and I am trying to find out which thread is responsible for it

      When I run htop and I sort by CPU usage I see that my application created many threads and especially 2 of them eating up the CPU

      PID User PRI NI VIRT RES SHR S CPU% MEM% TIME+ Command

      21997 root 16 0 2080M 1403M 129M S 100 18.3 5h35:28 /usr/lib/jvm/java-1.5.0-sun/bin/java -Dprogram.name=run.sh -server -Xms1024 -Xmx1024 -Dsun.rmi.dgc.client.gcInterval=3600000 ...........

      21998 root 17 0 2080M 1403M 129M R 92.8 18.3 4h28:52 /usr/lib/jvm/java-1.5.0-sun/bin/java -Dprogram.name=run.sh -server -Xms1024 -Xmx1024 -Dsun.rmi.dgc.client.gcInterval=3600000 ...........

      All other threads related to this application have CPU = 0%

      When I run jps, I see

      26596 Jps
      21997 Main

      When I run jstack 21997 > /tmp/jstack.21997 and view jstack.21997 then I don't see any information related to PID 21998

      Why is that? I am trying to get an understanding of what the thread 21998 is doing but why can't I see anything about it in the jstack dump of the process 21997 ?

      I would appreciate any help

      Thank you

        • 1. Re: Identifying the thread that is eating up my CPU
          Peter Johnson Master

          Are you, by any chance, running with the kernel option that shows each thread as its own process? I can't recall the option name off hand, but if you do a "ps -ef | grep java", how many entries do you get?

          Based on the jps output, I suspect that 21997 is the process (and the master thread for the process) while 21998 is just a thread.

          The best way to find out what is taking up all the processor is to run jstack several time, each time a few seconds apart, and look at the threads that are still in the same code. You can ignore the http threads waiting on objects - instead look for threads running your code.

          • 2. Re: Identifying the thread that is eating up my CPU
            Matthieu Labour Newbie

            Hi Peter
            Thank you for your reponse
            I am running on linux so each thread has a PID
            The main thread is 21997
            but htop shows that pid 21997 AND 21998 are eating the CPU but jstack 21997 does not provide anything on 21008
            It is like if htop is telling me processId 21997 created thread 21998 and thread 21998 is eating the CPU
            But jstack is telling me process 21997 doesn't have anything on thread 21998
            matt

            • 3. Re: Identifying the thread that is eating up my CPU
              Peter Johnson Master

              In my setup, the threads do not have process ids, so I cannot tell if the Java stack dump (jstack output) mentions the process id associated with each thread. But based on your observations, I would say that it doesn't. None the less, the thread identified as pid 21998 is in the jstack output. Like I wrote earlier, you might have to take several stack dumps, and compare them, to identify the busy thread.