JAVA DestroyJavaVM线程CPU使用率高

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

JAVA DestroyJavaVM thread high CPU

问题

我发现在应用程序启动时,DestroyJavaVM线程占用了99%的CPU(大约一个CPU核心)。我找不到关于此线程的任何文档。StackOverflow上的一个答案说这个线程除了加入其他非守护线程外什么都不做。这让我困惑,为什么在应用程序启动时它会使用这么多的CPU。我还发现有篇帖子说DestroyJavaVM线程是其他线程的父线程,top命令将所有子线程的使用率累积到父线程上。但是当我使用pstree命令显示Java线程树时,情况并不是这样。

英文:

I find DestroyJavaVM thread using 99% of the cpu (about one cpu core) when the application starts. I can not find any document for this thread. One answer in StackOverflow said that this thread does nothing but joins other no daemon threads. This confused me why it uses so much cpu when the application starts. I also find one post said that the DestroyJavaVM thread is parent thread of other thread, the top command accumulate all children use rate to parent. But when I use pstree comman to show java thread tree, that is not true.

答案1

得分: 4

DestroyJavaVM不是独立的线程。它实际上是一个启动VM关闭的Java线程,即最后一个非守护应用程序线程或调用System.exit()的线程。

当JVM即将终止时,它会将当前线程重命名为DestroyJavaVM,并使用此线程启动关闭序列。

对于简单应用程序,当所有业务逻辑从main方法调用时,当main方法返回时,将把主线程重命名为DestroyJavaVM。你观察到的可能只是主线程在执行其主要任务时消耗CPU。

英文:

DestroyJavaVM is not a separate thread. It's basically a Java thread that initiates VM shutdown, i.e. either the last non-daemon application thread, or a thread that calls System.exit().

When JVM is about to terminate, it renames the current thread to DestroyJavaVM and initiates the shutdown sequence using this thread.

In the case of a simple application, when all the business logic is called from the main method, it will be the Main thread that is renamed to DestroyJavaVM when the main method returns. What you observe is probably just the Main thread that consumes CPU for its primary job.

huangapple
  • 本文由 发表于 2020年4月6日 22:22:30
  • 转载请务必保留本文链接:https://go.coder-hub.com/61062002.html
匿名

发表评论

匿名网友

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

确定