In Haiti, a zombie is an "undead" person who has been cursed with vadoo. This inspired a classic
American horror flick, The Night of the Living Dead, in which all these dead people crawl out of their
graves and come after our heroes. This is the kind of thing that kernel hackers think about late at night.
Figure 4-4. Java Thread Create and Join
Is She Still Alive?
If you wish to know if a given thread is still running, you can call the method
thread.isAlive(). This will tell you if the thread was running when you called it, but by the
time you get around to using the information, it may have changed. In other words, between the
time you find out that the thread is alive and the time when you find something for it to do, the
thread may have exited. This is OK, because you don't really want to know that anyway. (If you
think you do, you're wrong. You really want to know something else.)
If you want to know when a thread has exited, you join it. If you want to give a thread something
new to do, you write the code so that the thread never exits, or so that the thread exits only on
In short, the method isAlive() is pretty useless. Several other methods are similar. The
activeCount() method tells you how many threads were running when you called it. The
enumerate() method promises to fill an array you supply with as many of the currently running
thread objects as fit. By the time you use any of the information these methods supply, it may be
out of date. Don't do that.
Once a thread has exited, it is gone. The stack has been freed, the internal thread structures have
been cleared, the underlying kernel resources have been returned. All that's left is the empty shell
of the thread object. (If you extended the thread object and included your own instance variables,
those will not be changed.) You cannot restart the thread; you cannot reuse the thread object. It's
gone, dead, deceased, passed on, unrevivable.
Search WWH :