Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Checking the state of a thread  RSS feed

 
Vikram Sah
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a background thread running. On the event of this thread death I have to perform an action.
How will I check the state of the thread whether its alive or dead.
 
Charles Lyons
Author
Ranch Hand
Posts: 836
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The isAlive() method on Thread?

Though without referring to named instances of Thread, you could also check when the Runnable task's execution has finished since the thread should reach the end of the run() method - unless the thread somehow dies without returning from run() but I don't see how that can happen unless the program is terminated (in which case who cares?!). That way you'd register a listener which is invoked in run() right at the end, just before it returns. Then you wouldn't need to keep checking the status of the thread as you'd receive synchronous notification.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!