This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Customer Requirements for Developers and have Marcho Behler on-line!
See this thread for details.
The moose likes Threads and Synchronization and the fly likes The Thread object Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Customer Requirements for Developers this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "The Thread object" Watch "The Thread object" New topic
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: 24189
    
  34

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)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: The Thread object
 
It's not a secret anymore!