Michael said:
It becomes *egligible* for garbage collection when its run() method
has finished executing. When it will actually *be* garbage collected
is up to the JVM to decide.
It would be more accurate to say that it will not be eligible for
garbage collection until after its run() method is completed. Thread
instances are not immune to general considerations of reachability, so
the thread is free to store off references to its Thread instance, which
could be obtained from Thread.currentThread(), where ever it likes,
which could cause that Thread instance to greatly outlive the thread
itself.
In any case, it's rarely of use to enumerate all the conditions for a
specific object to become eligible for garbage collection. You're
better off going by the geberal rule that an object is always eligible
for garbage collection the instant that it becomes inaccessible. Since
the current Thread instance is accessible for a running thread (via
Thread.currentThread()), everything said so far falls within that
statement... but it's not nearly so complex as all that.
--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.
Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation