Thread life cycle

Source: Internet
Author: User

Thread life cycle thread state transitions

Thread state
    1. Newly created (new)

      Creates a thread.Thread t = new MyThread();

    2. Ready (runnable)

      The thread is in a state that can be scheduled for CPU at any time. Executes the start() boot thread.

    3. Run (running)

      Threads are scheduled by the CPU and run continuously. Calls yield() can yield CPU resources (not necessarily).

    4. Blocking (blocked)

      runninga thread in the state temporarily abandons the use of the CPU for some reason, stops execution until it enters the ready state, and then has the opportunity to be scheduled again by the CPU.

      • Wait for blocking: execution wait() causes the thread to hang (locks are released). notify() notifyAll() The thread will not enter the state until the thread gets or messages runnable .

      • Synchronization blocking: Failed to get synchronized synchronization lock.

      • Other blocking:

        • Execution sleep(milliseconds) (aborts execution at a given time, does not release the lock);
        • Execution join() joins a thread, the original thread is suspended until the target thread ends;
        • A request was made I/O .
    5. Death (dead)

      End of thread run (thread task execution complete/exception exit).

Thread life cycle

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.