Threads
Answer: Since Thread is also an Object, it will only garbage collected when the
reference count is zero. 
You may think it is quite non sense. the thread is useless when it enter "dead" state.
why not garbage collect it? That s because the thread object itself may contain some
other useful information even the thread  dead , e.g. the result of the execution of the
thread. Thus, it is not sensible to do garbage collect when the reference count is not
zero.
Hope this answer your question.
  
Anthony
 Q: How exactly does join() work?
I looked up the specs and all it says is that it waits for the thread to die. How does the
thread die?, do I give it an explicit command?
Answer: A thread finishes when the run() method of its Runnable object returns, or
when the thread calls Thread.exit().
The thread also finishes if the run method throws an error or exception, including the
one produced by calling Thread.stop()or if it falls through to the end of the run body.
Patricia
 Q: I would like to ask a question about garbage collection of Thread Object.
When will a Thread Object be garbaged collected? 
When the reference count to it becomes zero, or when it enters the "Dead" state, i.e.
the run() member function terminates?
Answer, part1: Since Thread is also an Object, it will only garbage collected when
the reference count is zero.  You may think it is quite non sense. the thread is
useless when it enter "dead" state. why not garbage collect it?
That s because the thread object itself may contain some other useful information
even the thread dead , e.g. the result of the execution of the thread. Thus, it is not
sensible to do garbage collect when the reference count is not zero.
  
Anthony
P.S. Important ad! Except when object A holds a reference only to object B and
object B holds a reference only to object A. Both reference counts are non zero, but
both objects are eligible for garbage collection. Which is why few, if any, modern
VMs use reference counting to determine eligibility for garbage collection. 
Jim
Answer, Part 2: You can consider a Thread object as a normal Object for garbage
collection purposes if you consider this one rule: A running thread will not be garbage
collected.
That is, a normal running thread is a root object, so the Garbage Collector will not
attempt to mark it for collection. When the thread is not running, though, normal
Garbage Collection rules apply (i.e. total # references == 0 then collect).
To get a thread with different behavior, 
see the Thread.setDaemon(boolean bState) method.
  Brian
file:///F|/a_jsite/350_tips/threads.htm (3 of 4) [2001 07 08 11:25:00]






footer




 

 

 

 

 Home | About Us | Network | Services | Support | FAQ | Control Panel | Order Online | Sitemap | Contact

java web hosting

 

Visionwebhosting.net Business web hosting division of Web Design Plus. All rights reserved