Understanding java-17.3 thread state from the beginning

Source: Internet
Author: User

In this chapter we discuss the state of the thread.

1. Status

(1) New status (new): Newly created Thread object

(2) Ready State (Runnable): After the thread object is created, other threads call the object's start () method. The state of the thread is located in a pool of running threads that becomes operational and waits for the CPU to be used.

(3) Blocking state (Blocked): When a task wants to acquire an object lock, but the lock is held by another task, the state of the task is blocked state, and when the lock object is held to release the lock, then the task holds the lock, at which point the task is non-blocking state.

(4) Wait state (waiting): When the thread waits for another thread to notify the scheduler to wake execution. This state is more present when Object.wait,thread.join and other methods are executed.

(5) Timed Wait (time waiting): The wait status of the enhanced version, increased the waiting period, when the time-out or received notification, the thread will wake up execution.

(6) Death status (Terminate): The thread finishes executing or exits the run () method due to an exception, and the thread ends the life cycle.


2. Attention points

The blocking state is not the same as the wait state.

The condition of blockage formation is related to the holding of locks.

The wait state is not necessarily related to the hold of the lock, it is related to some execution methods


3. State diagram




Summary: This chapter focuses on the state of the thread.


This chapter is here, thank you.

-----------------------------------

Directory



Understanding java-17.3 thread state from the beginning

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.