From the Java API doc:
The Java Virtual Machine continues to execute threads until following occurs:
All threads that are not daemon threads have died, either by returning from the call to the run method or by throwing an exception that propagates beyond the run method.
I hope my assumption is correct that once thread finishes its run()
method it becomes eligible for garbage collection. In the same context I am just curious to know about:
- If it doesn't become eligible for garbage collection after returning
from
run()
, should one set its reference tonull
to do that? - Being eligible for garbage collection doesn't necessarily mean that the object will be removed from memory. It is at the sole discretion of the underlying operating system / JVM when it is garbage collected. But how can one make sure (either through a Java program or external tool) that the object is completely removed from the memory?
- If a thread is said to be dead once it finishes its run() method, why
can I still be able to execute
isAlive()
orgetState()
on the same thread object? Both the calls returnfalse
andRUNNABLE
respectively.