OpenJDK11 jstack output explanation

915 views Asked by At

I am trying to understand what the "cpu" and "elapsed" fields mean in a jstack thread dump in java 11. I have the following details for a thread, where jstack was executed three times quickly:

"Thread 1 " daemon prio=5 os_prio=0 cpu=0.13ms elapsed=51.03s tid=0x00007fe9c4024000 nid=0x2c11 waiting on condition  [0x00007fe500284000]
   java.lang.Thread.State: TIMED_WAITING (parking)
"Thread 1 " daemon prio=5 os_prio=0 cpu=0.13ms elapsed=56.96s tid=0x00007fe9c4024000 nid=0x2c11 waiting on condition  [0x00007fe500284000]
   java.lang.Thread.State: TIMED_WAITING (parking)
"Thread 2" daemon prio=5 os_prio=0 cpu=0.10ms elapsed=1.35s tid=0x00007fe9c4024000 nid=0x2da1 waiting on condition  [0x00007fe4a0311000]
   java.lang.Thread.State: TIMED_WAITING (parking)

After TIMED_WAITING, rest of the message is exactly same in all the three threads. My question is, why does elapsed time suddenly decrease on the third 1, even when tid is the same? In my application, thread name keeps changing, so it doesn't necessarily imply that a different thread name corresponds to a different thread. Can it happen that the old thread died and the same tid was quickly reused? If someone could link any official doc on the explanation of the dump, that would be helpful. (NOTE: My threads belong to a thread pool)

I could only find the cpu and elapsed explanation at https://bugs.openjdk.org/browse/JDK-8200720. But doesn't really help.

1

There are 1 answers

4
Holger On

The third output obviously contains a different thread. If you do not trust the different name, trust the different nid. Further, taking the output “elapsed=1.35s” for granted, it literally means that the thread only ran for a bit more than a second at this point, so it’s perfectly plausible that the thread has been started between your jstack calls.

When your third jstack output does not contain the first thread and you didn’t filter, it indicates that the first thread has terminated in-between the second and third call, which explains why these two threads can have the same tid. Since this is not a thread id but a memory address, freeing the old thread object allows to reuse the memory for a new thread object.

As said, use the nid instead, to decide whether you are looking at the same or a different thread.

You can find different articles explaining the attributes in the internet, but I could not find one that qualifies as an official documentation, though.