Several available states of threads

Source: Internet
Author: User

Several available states of threads
1. new ):A new thread object is created.2. runnable ):After a thread object is created, other threads (such as the main thread) Call the start () method of the object. The thread in this status is located in the runable thread pool and is waiting to be selected by the thread scheduling to obtain the cpu usage right.3. Run (running ):The runnable thread obtains the cpu time slice and executes the program code.4. block ):The blocking status means that the thread gives up the cpu usage for some reason, that is, it gives up the cpu timeslice and stops running temporarily. It is not until the thread enters the runnable state that the cpu timeslice is re-obtained to the running state. Blocking is divided into three types:(1). Waiting for blocking:The running thread executes the o. wait () method, and the JVM puts the thread into the waiting queue (waitting queue.(2). Synchronization blocking:When a running thread obtains the synchronization lock of an object, if the synchronization lock is occupied by another thread, the JVM puts the thread into the lock pool.(3) Other blocking:The running Thread executes the Thread. sleep (long MS) or t. when the join () method or an I/O request is sent, JVM sets this thread to blocking. When the sleep () status times out, the join () waits for the thread to terminate or times out, or the I/O processing is completed, the thread is re-transferred to the runnable status.5. dead ):The execution of the run () and main () Methods ends, or the run () method exits due to an exception. The dead thread cannot be re-generated.

Related Article

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.