The life cycle of threads in Java can be broadly divided into 5 states.
①new: This refers to the creation of an object of the thread class (or its subclasses) with the NEW keyword
②runnable: This situation refers to the object of the thread class calling the start () method, when the thread waits for the time slice to rotate to itself, in order to get the CPU, and the second is that the thread does not run its own run method when it is in the RUNNABLE state. When the time slice is exhausted, return to the runnable state, and there is a situation where the thread in blocked state returns to the Runnable state after the current blocked state has ended.
③running: The thread at this point is the runnable thread that gets the CPU, and the RUNNING state is the state that all the threads want to get.
④dead: A thread in the running state becomes a DEAD state after the Run method is executed.
⑤blocked: This state refers to a thread in the running state, for some reason, such as calling the Sleep method, waiting for user input, and giving up the current CPU to another thread.
The reason that a thread in the runnable state becomes blocked state, except that the thread calls the sleep method, waits for an input reason, and that the join method of another thread is called in the current thread, and that the method is locked when accessing an object's method.
Accordingly, when a thread in the blocked state goes to the runnable state by that state when the following conditions are met: The Sleep thread wakes (the time of sleep), obtains the user's input, ends the other thread that called the join, and obtains the object lock.
In general, both the thread in runnable and the thread in the running state switch to each other until the Run method is finished and the thread ends and enters the dead state.
The life cycle of threads in Java can be broadly divided into 5 states