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.
posted 9 years ago
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.
Charles Lyons (SCJP 1.4, April 2003; SCJP 5, Dec 2006; SCWCD 1.4b, April 2004)
Author of OCEJWCD Study Companion for Oracle Exam 1Z0-899 (ISBN 0955160340 / AmazonAmazon UK )