wood burning stoves 2.0*
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
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: 24183
    
  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
 
Similar Threads
Difference between run and start method of Thread
javaprepare.com mock exam
Deadlock
Thread and Object
I can't synchronize my threads properly