Thread state Transition Description

Source: Internet
Author: User

Threads under certain conditions, the state is changed,

Threads have a total of several states: 1, new State (new): a newly created thread object.
2, Ready State (Runnable): After the thread object was created, other threads called the object's start () method. The thread of this state is in the "Run thread pool" and becomes operational, waiting only for the right to use the CPU. That is, in the ready state of the process, in addition to the CPU, all other operational resources are available.
3, running State (Running): The ready state of the thread to get the CPU, execute program code.
4, blocking state (Blocked): Blocking state is the thread for some reason to give up the use of CPU, temporarily stop running. Until the thread enters the ready state, there is an opportunity to go to the running state.
The blocking situation is divided into three types:
A, wait for blocking: The running thread executes the wait () method, which releases all the resources it occupies, and the JVM puts that thread into the waiting pool. After entering this state, it is not automatically awakened, and must rely on other threads to invoke the Notify () or Notifyall () method to be awakened.
B, synchronous blocking: When a running thread acquires a synchronized lock on an object, the JVM puts the thread into the lock pool if the synchronization lock is occupied by another thread.
C, other blocking: The running thread executes the sleep () or join () method, or when an I/O request is made, the JVM puts the thread into a blocking state. When the sleep () state times out, join () waits for the thread to terminate or timeout, or the I/O process completes, the thread is back in ready state.

5. State of Death (Dead): The thread has finished executing or exited the run () method because of an exception, which ends the lifecycle.

state Transition logic diagram:





Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.