Reputation: 1389
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..
Upvotes: 1
Views: 1074
Reputation: 1368
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.
Upvotes: 0
Reputation: 719396
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.
Upvotes: 3
Reputation: 59634
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.
Upvotes: 1