[ACCEPTED]-Getting the Java thread id and stack trace of run-away Java thread-jstack

Accepted answer
Score: 13

It looks like the nid in the jstack output 7 is the Linux LWP id.

"http-342.877.573.944-8080-360" daemon prio=10 tid=0x0000002adaba9c00 nid=0x754c in Object.wait() [0x00000000595bc000..0x00000000595bccb0]

Convert the nid to decimal 6 and you have the LWP id. In your case 0x754c 5 is 30028. This process is not shown in our 4 ps output, but it was probably one of the 3 LWPs you have omitted to save space.

Here's 2 a little a Perl snippet you can use to pipe 1 the output of jstack to:

#!/usr/bin/perl -w
while (<>) {
    if (/nid=(0x[[:xdigit:]]+)/) {
        $lwp = hex($1);
        s/nid=/lwp=$lwp nid=/;
    }
    print;
}
Score: 7

You can use JConsole to view the thread's stack 11 trace.

If your using JDK 1.6.0_07 or above, you 10 can also use visualvm.

Both tools provide a nice 9 view of all the running threads in an application. The 8 visualvm is quite a bit nicer, but hopefully 7 seeing all the threads can help you track 6 down the run-away thread.

Check for threads 5 that are always in a state of RUNNING. When we 4 had a run-away thread, the stack trace would 3 constantly change. So we were able to tell 2 which methods the loop was calling, and 1 track down the loop.

Score: 1

Nice,useful answers!

For Linux, use ps -efL, -L 3 option will show the LWPs. As a side note, the
"http-342.877.573.944-8080-360" daemon prio=10 means 2 "ThreadName(as given by the JVM)" runningmode(inherited from 1 the pid) priority(inherited from the pid)

Score: 0

From memory if you CTRL-BREAK on the console 13 you will get a dump of the current threads 12 and a few of their stack trace frames.

From 11 memory (I'm not sure if this is an IntelliJ 10 IDEa feature, or it is default in java) but 9 it will tell you which thread is deadlocked, and 8 which object they are waiting on. You should 7 be able to redirect the output to a file, and 6 just grep for the DEADLOCKED text.

JConsole, VisualVM 5 or other profilers such as JProfiler will 4 also show you the threads and their stacks, however 3 if you don't want to use any external tool 2 I think CTRL-BREAK will give you what you're 1 looking for.

Score: 0

On SUN

Note that prstat by default shows the no of light 5 weight processes , not the LWPID.

To see 4 information for all the lightweight processes 3 for a particular user use the -L option.

prstat -L -v -u weblogic

now 2 use the LWPID and convert it into hex and 1 match it with the nid from the thread dump

More Related questions