When does a Java Thread reach the 'Die' State
In Java, Die is one of the states on a thread.
What causes a thread to enter this state?
Solution 1:
From the Thread API, here is a complete list:
- If the run() method returns.
- If an exception is thrown that propagates beyond the run method.
- If it is a daemon thread and all non-daemon threads have 'died'
- If the exit method of class Runtime has been called (even at another thread).
Solution 2:
All Thread
s die either by returning from the call to the run
method or by throwing an exception that propagates beyond the run
method.