State transitions between JAVA threads __java

Source: Internet
Author: User


State transitions between threads:

1. NEW: A new Thread object was created.

2. Operational (runnable): When a thread object is created, other threads (such as the main thread) invoke the object's start () method. The thread in the state is in the running thread pool, waiting to be selected by the thread dispatch to obtain the right to use the CPU.

3. Run (running): The Running State (runnable) thread obtains the CPU time slice (timeslice), executes the program code.

4. Blocking (block): Blocking state refers to the thread for some reason to give up the use of CPU, that is, let the CPU TimeSlice, temporarily stop running. Until the thread enters a running (runnable) state, it has the opportunity to get the CPU TimeSlice to the running (running) state again. The blocking situation is divided into three types:

(i). Wait for blocking: The running (running) thread executes the o.wait () method, and the JVM puts that thread into the wait queue (waitting queue).

(ii). Synchronous blocking: A thread that runs (running) is placed in the lock pool if the synchronization lock is occupied by another thread when it acquires a synchronized lock on the object.

(iii). Other blocking: The running thread executes the thread.sleep (long ms) or T.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 transferred back into a runnable state.

5. Death (dead): Thread Run (), the main () method finishes executing, or the run () method is exited because of an exception, the thread ends the lifecycle. The thread of death cannot be resurrected again.

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.