Multi-threaded Java study notes - the thread state

Thread state is shown: a total of five states, the new (New), Ready (Runnable), running (Running), blocked (Blocked), death (Dead)

New Status: In a program thread object is created, for example: Thread t = new Thread () a new state in case the thread, the thread of the code has not been performed;

Ready state: As the name suggests That thread is ready to execute stage, ready to be cpu scheduling. When you call the thread object toStart () method, the thread into the ready state, this time to perform and does not immediately run () method, the thread must also compete with other thread CPU time, CPU time before they can obtain only run thread.

Operating status: When the thread gets CPU time slice, it only went into operation, really started run () method in the code. When possible consumed a time slice, the code RUN () is not executed in the end, but this time the thread enters the Runnable state, the thread can wait for the next time slice are scheduled cpu, the thread is Runnable, alternately switching Running the process of;

Blocked state: when a thread in the Running state, the following conditions are met, causes the thread into the blocked state (Blocked). Thread is blocked, and after blocking waiting for the end, will enter the Runnable state, waiting to get CPU time slice and continue the program.

   (1) wait for obstruction - by calling the thread wait () method, thread to wait for the completion of a job.
   (2) synchronous blocking - a thread get synchronized synchronous lock failure (because the lock was occupied by another thread), it will enter synchronous blocking state.
   (3) the blocked - by sleep () or join the calling thread () or issue the I / O request, the thread will enter into blocking state. When the sleep () timeout, join () (Part II study) wait for the thread to terminate or a timeout, or I / O processing is completed, the thread into the ready state again.

Death state: When the thread execution is over or due to abnormal exit the run () method, thread life cycle.

Guess you like

Origin www.cnblogs.com/ldh666/p/10993860.html
Recommended