OpenJDK11 jstack输出解释

huangapple go评论64阅读模式
英文:

OpenJDK11 jstack output explanation

问题

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)

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.

英文:

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

得分: 1

第三个输出显然包含一个不同的线程。如果您不信任不同的名称,请信任不同的 nid。此外,将输出中的“elapsed=1.35s”视为事实,这实际上意味着该线程仅在此时运行了一秒多一点,因此很有可能该线程在您的两次 jstack 调用之间已经启动,所以这两个线程具有相同的 tid 是完全合理的。由于这不是线程 ID 而是内存地址,释放旧线程对象可以重用内存来创建新的线程对象。

正如我所说,使用 nid 来判断您是否正在查看相同的线程或不同的线程。

您可以在互联网上找到解释这些属性的不同文章,但我找不到一个可以被视为官方文档的文章。

英文:

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.

huangapple
  • 本文由 发表于 2023年6月15日 02:37:30
  • 转载请务必保留本文链接:https://go.coder-hub.com/76476637.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定