JDK-4520729 : (spec thread) Documentation for Thread.isAlive() should be more clear
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.lang
  • Affected Version: 1.4.0
  • Priority: P4
  • Status: Closed
  • Resolution: Not an Issue
  • OS: generic
  • CPU: generic
  • Submitted: 2001-10-29
  • Updated: 2007-04-23
  • Resolved: 2007-04-23
Related Reports
Relates :  
Description

Name: rmT116609			Date: 10/29/2001



We are using Thread.isAlive() to determine whether a thread has exited its run() method 
and are not sure if this is an appropriate way to check this.

Could you please add  more information to the documentation explaining exactly
what Thread.isAlive() == false tells us?

----------------------------------------------------------------------------
Currently the documentation says:

"Tests if this thread is alive. A thread is alive if it has been started and has not yet died"

Specifically my concerns are:

1) I assume, "A thread is alive if it has been started" means Thread.start()
has been called? or does it mean its run method has started?

2) "has not yet died" :  Does this mean the object's run() method has exited? -
or is there some cleaning up that the VM may be doing after the run method
exits before isAlive() will return false?
(Review ID: 134608) 
======================================================================

Comments
EVALUATION 1) I assume, "A thread is alive if it has been started" means Thread.start() has been called? or does it mean its run method has started? It means the former, but the latter cannot be specified, as the change of state returned by isAlive isn't accomplished in the run method, but in the "system". It's possible for the thread intending to invoke the run method to be suspended for an indefinite time, so isAlive could return true before run gets a chance to execute (possibly ever). 2) "has not yet died" : Does this mean the object's run() method has exited? - or is there some cleaning up that the VM may be doing after the run method exits before isAlive() will return false? If by "exited" you mean "returned", it means "after" this return, or else after an uncaught exception has been thrown before the run method can return. This is the mirror image of the starting scenario, and the specification can't say exactly when after the run method stops executing isAlive returns false, but in both cases the thread is "dead."
23-04-2007