Java threads may be in several states, and at any point in time a thread can only be in one state.
1. New State (new): a thread that has not been started since it was created is in this state.
Transfer opportunity: Create a new thread.
2. Ready state (Runnable): called the Start () method, the thread of that state is in a pool of running threads, becomes operational, and waits for the CPU to be used.
Transfer time: Call the Start () method.
Threads in the running state are selected by the CPU to execute other threads.
Execution Thread.yeild (), not guaranteed.
3. Running state (Running): The ready state of the thread obtains the CPU's execution and is executing the Run method.
Timing of transfer: Get the CPU execution right.
4. Blocking (Blocked): When a running thread acquires a synchronization lock on an object, the JVM puts the thread into the lock pool if the synchronization lock is occupied by another thread.
Transfer time: There are already other threads executing the synchronization code snippet, waiting for a sync lock.
5. No-time Wait (waiting): Will not be allocated CPU execution events, to wait for other lines to wake up Cheng, the following methods cause the thread to fall into an age-free wait:
Transfer timing: Object.wait () method with timeout parameter not set
Thread.Join () method with timeout parameter not set
6. Term wait (time waiting): Also not be assigned CPU execution events, but do not have to wait for other lines Cheng wake up, after a certain period will be automatically awakened by the system. The following methods cause threads to fall into the waiting period:
Transfer timing: Set the Object.wait () method of the timeout parameter
Set the Thread.Join () method of the timeout parameter
Thread.Sleep (Long) method
7. End (Terminated): The thread has finished executing and the Run method exits.
Java concurrent Programming 5_ thread state