| Author |
The Thread object
|
ravinderSingh singh
Ranch Hand
Joined: Nov 18, 2004
Posts: 41
|
|
Hello, Is a thread only represented by a single Thread object? In other words, when you invoke the Thread.currentThread() method does this method return a reference to the same Thread object that was used to create the thread? One more thing, is the Thread object representing a thread ever garbage collected if there are no references to the object? Thanks
|
 |
Ernest Friedman-Hill
author and iconoclast
Marshal
Joined: Jul 08, 2003
Posts: 24081
|
|
The answer to your first two questions are "yes". There is a single Thread object for each thread. "Live" Thread objects always belong to a ThreadGroup, which keeps references to them. Therefore, a runnable Thread can never be garbage collected. They become eligible for collection after they are stopped.
|
[Jess in Action][AskingGoodQuestions]
|
 |
Georgy Bolyuba
Ranch Hand
Joined: Feb 18, 2005
Posts: 162
|
|
Originally posted by ravinderSingh singh: Is a thread only represented by a single Thread object? In other words, when you invoke the Thread.currentThread method does this method return a reference to the same Thread object that was used to create the thread?
Yes.
One more thing, is the Thread object representing a thread ever garbage collected if there are no references to the object?
gc will not collecte Thread if Thread is working. Even when there is no references to the Thread object.
|
SCJP 1.4 (100%) Done.<br />SCJD (URLyBird 1.2.3 Started)
|
 |
 |
|
|
subject: The Thread object
|
|
|