State transitions between Java threads

Source: Internet
Author: User

state transitions between threads:  

1. New: A new Thread object has been created.

2. Operational (runnable): After the thread object is created, other threads (such as the main thread) call the object's start () method. The thread in this state is in a pool of running threads, waiting for the thread to be dispatched to get the CPU right.

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

4. Block: Blocking state refers to a thread that has given up the CPU for some reason, or let the CPU TimeSlice, temporarily stop running. Until the thread enters the operational (runnable) state, there is a chance to get the CPU TimeSlice again to the run (running) state. There are three types of blocking:

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

(b). Synchronous blocking: When a thread running (running) acquires a synchronization lock on an object, if the synchronization lock is occupied by another thread, the JVM puts the thread into the lock pool.

(iii). Other blocking: The thread that runs (running) executes the thread.sleep (long ms) or T.join () method, or when an I/O request is made, the JVM will place the thread in a blocked state. When the sleep () state time-out, join () waits for the thread to terminate or times out, or the I/O process is complete, the thread is re-transferred to the operational (runnable) state.

5. death (dead): The thread Run (), main () method execution ends, or the run () method is exited due to an exception, the thread ends the life cycle. The thread of death cannot be resurrected again.

State transitions between Java threads

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.