Thread state from a large aspect, can be summed up as: the initial state, operational status, non-operational state and extinction state, the specific can be subdivided into the 7 states shown below:
1) The implementation of the thread has two ways, one is to inherit the thread class, and the other is to implement the Runnable interface, but anyway, when we new thread instance, the thread enters the initial state;
2) When the object calls the start () method, it enters the operational state;
3) After entering the operational state, when the object is selected by the operating system, the CPU time slice will go into the running state;
4) After entering the state of operation, the case is much more, there is a general situation: when the. Run () method or the main () method ends, the thread enters the terminating state, and when the thread calls its own sleep () method or another thread's join () method, it goes into a blocking state that stops the current thread. But does not release the resources it occupies). When
After the end of sleep () or join (), the thread enters the operational state, waits for the OS to allocate time slices, and when the thread has just entered the operational state (note that it is not yet running), discovers that the resource to be called is locked (synchroniza,lock) and will immediately enter the lock pool state. Wait for the lock tag (the lock pool may already have other lines
Process is waiting to acquire the lock tag, when they are in the queue state, on a first-come-first-served basis, once the thread acquires a lock tag, it goes into the operational state, waits for the OS to allocate CPU time slices, and when the thread calls the Wait () method, it enters the waiting queue (which frees up all the resources in the State, After entering this state,
is not automatically awakened, you must rely on other threads to invoke the Notify () or Notifyall () method to be awakened (because notify () just wakes up a thread, but we are not sure which thread is specifically awakened, perhaps the thread we need to wake up to cannot be awakened, Therefore, in practice, the Notifyall () method is used to awaken
thread), the thread is awakened and enters the lock pool, waiting for the lock token to be acquired. When a thread calls the Stop method, the thread goes extinct, but because the stop method is unsafe and discouraged, you can implement the thread stop by using the conditions in the Run method.