Java concurrent Programming 5_ thread state

Source: Internet
Author: User

Java threads may be in several states, and at any point in time a thread can only be in one state.

1. New State (new): a thread that has not been started since it was created is in this state.

Transfer opportunity: Create a new thread.

2. Ready state (Runnable): called the Start () method, the thread of that state is in a pool of running threads, becomes operational, and waits for the CPU to be used.

Transfer time: Call the Start () method.

Threads in the running state are selected by the CPU to execute other threads.

Execution Thread.yeild (), not guaranteed.

3. Running state (Running): The ready state of the thread obtains the CPU's execution and is executing the Run method.

Timing of transfer: Get the CPU execution right.

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

Transfer time: There are already other threads executing the synchronization code snippet, waiting for a sync lock.

5. No-time Wait (waiting): Will not be allocated CPU execution events, to wait for other lines to wake up Cheng, the following methods cause the thread to fall into an age-free wait:

Transfer timing: Object.wait () method with timeout parameter not set

Thread.Join () method with timeout parameter not set

6. Term wait (time waiting): Also not be assigned CPU execution events, but do not have to wait for other lines Cheng wake up, after a certain period will be automatically awakened by the system. The following methods cause threads to fall into the waiting period:

Transfer timing: Set the Object.wait () method of the timeout parameter

Set the Thread.Join () method of the timeout parameter

Thread.Sleep (Long) method

7. End (Terminated): The thread has finished executing and the Run method exits.

Java concurrent Programming 5_ thread state

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.