守护线程垃圾收集器的父线程是什么?

发布于 2024-11-05 14:12:41 字数 48 浏览 1 评论 0原文

垃圾收集器是一个守护线程,由 JVM 调用和控制。它有父线程吗?我对此有点困惑..

The garbage collector is a daemon thread which is invoked and controlled by the JVM. Does it have a parent thread? I am a little bit confused by this..

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

夜声 2024-11-12 14:12:41

Java不记录任何线程的(创建)父线程,并且(假设的)父子关系对线程的工作方式没有影响。

Java 与此最接近的是线程组的概念。每个线程都是线程组的成员,线程组可以包含其他线程组,线程组形成以初始线程组为根的可导航树。然而,考虑到通过 ThreadGroup 挂起/恢复/终止线程是危险的并且不推荐使用,ThreadGroup 并不允许您做太多事情。

垃圾收集器线程可能是初始线程组的成员。但是,GC 线程也可能是一种特殊情况,而不是任何 ThreadGroup 的成员。不管怎样,它不会影响任何东西......除非你编写一个遍历 ThreadGroup 树的程序。

守护进程线程只是在启动之前设置了守护进程标志的线程。这与ThreadGroup机制无关。

Java does not record the (creation) parent thread of any thread, and the (hypothetical) parent-child relationship has no bearing on the way that threads work.

The closest thing that Java has to this is the concept of a ThreadGroup. Every Thread is a member of a ThreadGroup, ThreadGroups can contain other ThreadGroups, with the ThreadGroups forming a navigable tree rooted in the initial ThreadGroup. However, ThreadGroups don't really allow you to do much, given that suspending / resuming / killing threads by ThreadGroup is dangerous and deprecated.

The garbage collector threads are possibly a member of the initial ThreadGroup. However, it is also possible that the GC threads are a special case and not a members of any ThreadGroup. Either way, it doesn't affect anything ... unless you write a program that traverses the ThreadGroup tree.

Daemon threads are simply threads that have had the daemon flag set before they were started. This is independent of the ThreadGroup mechanism.

通知家属抬走 2024-11-12 14:12:41

不,没有。守护线程继续运行,直到您调用 exit() 或所有非守护线程都已死亡。

换句话说,并不是因为你在另一个线程中创建了一个线程,它们之间就是父子关系。他们有独立的生活。

No there is not. Daemon thread carry on running until either you call exit() or all non-daemon threads are dead.

In other words, it is not because you create a thread within another thread that their is a parent-child relationship between them. They have an independent life.

梅倚清风 2024-11-12 14:12:41

如果每个 java 线程都映射到您正在使用的操作系统中的 lwp,则 JVM 默认创建的所有线程都是启动 java 进程本身的父进程的子进程。因此,Java 进程内没有用于垃圾收集线程的父进程。因此,诸如垃圾收集线程、终结器和引用处理程序线程之类的线程与主线程一样都是java进程的父进程的子进程。

您可以在 Solaris 计算机上查看 ps -elL 的输出来确认这一点。

我想这回答了你的问题。如果没有请返回。

In case each java thread is mapped to a lwp in the OS you are using, all the threads that JVM creates by default are children of the parent process which starts the java process itself. So, there is no parent within the java process for garbage collection thread. So, threads like garbage collection thread, finalizer and reference handler thread are all children of parent process of java process along with the main thread.

You can look at the output of ps -elL on a Solaris machine to confirm this.

I think this answers your question. Please revert back if not.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文