In Java, Die is one of the states on a thread.
What causes a thread to enter this state?
A thread dies naturally when its run() method exits normally. For example, the while loop in this method is a finite loop--it will iterate 100 times and then exit. A thread with this run() method will die naturally after the loop and the run() method completes.
A thread is automatically destroyed when the run() method has completed. But it might be required to kill/stop a thread before it has completed its life cycle. Previously, methods suspend(), resume() and stop() were used to manage the execution of threads.
In this case, Thread will be moved from “ Running ” state to “ Waiting ” state with specified waiting time. This can be done whenever we want currently running thread to wait for some specified amount of time. Once the specified amount of time is completed, then the waited thread will be moved to “ Runnable ” state.
The active state contains two states within it: one is runnable, and the other is running. Runnable: A thread, that is ready to run is then moved to the runnable state. In the runnable state, the thread may be running or may be ready to run at any given instant of time.
From the Thread API, here is a complete list:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With