Several States of JAVA threads and several java threads
A thread can have six states:
1. New (New)
2. Runnable (runable) (running)
3. Blocked (Blocked)
4. Waiting (Waiting)
5. Timed waiting)
6. Terminated (Terminated)
New thread:
When a new Thread, such as new Thread (r), is created using the new operator, the Thread has not started running and its current status is new, there is still some basic work to be done before the thread runs.
Runable thread:
Once the thread calls the start method, the thread is in the runnable state. In this state, the thread may be running or not running (that is to say, the running thread in the Java specification is still running ). After the thread is running or after it is returned from the blocking, waiting, or sleep status, it also returns to the runable status.
Blocked thread:
In this state, the synchronization operation is performed on multiple threads, such as waiting for the release of the synchronized block of another thread, or calling wait () in the re-imported synchronized block () method, that is, the thread is waiting to enter the critical section.
Waiting thread:
In this state, the thread calls its wait method after it has a lock, or the thread calls the join method to join another thread, the status of the thread waiting to be joined. The difference between the blocking status and the waiting status should be distinguished here. One is waiting for entry outside the critical point, and the other is wait in the critical point.
Timing wait thread:
When a Thread calls a method with a timeout parameter, the Thread enters the timer wait state. The methods with supermarket parameters include Thread. sleep, Object. wait, Thread. join, Lock. tryLock and Condition. the timing version of await.
Terminated thread:
1) The thread naturally dies because the run method Exits normally.
2) The run method is terminated due to an uncaptured exception and an unexpected death occurs.
Conversions between thread states: