Several States of JAVA threads and several java threads

Source: Internet
Author: User

Several States of JAVA threads and several java threads

A thread can have six states:

1. New (New)

2. Runnable (runable) (running)

3. Blocked (Blocked)

4. Waiting (Waiting)

5. Timed waiting)

6. Terminated (Terminated)

 

New thread:

 When a new Thread, such as new Thread (r), is created using the new operator, the Thread has not started running and its current status is new, there is still some basic work to be done before the thread runs.

Runable thread:

  Once the thread calls the start method, the thread is in the runnable state. In this state, the thread may be running or not running (that is to say, the running thread in the Java specification is still running ). After the thread is running or after it is returned from the blocking, waiting, or sleep status, it also returns to the runable status.

Blocked thread:

  In this state, the synchronization operation is performed on multiple threads, such as waiting for the release of the synchronized block of another thread, or calling wait () in the re-imported synchronized block () method, that is, the thread is waiting to enter the critical section.

Waiting thread:

In this state, the thread calls its wait method after it has a lock, or the thread calls the join method to join another thread, the status of the thread waiting to be joined. The difference between the blocking status and the waiting status should be distinguished here. One is waiting for entry outside the critical point, and the other is wait in the critical point.

Timing wait thread:

When a Thread calls a method with a timeout parameter, the Thread enters the timer wait state. The methods with supermarket parameters include Thread. sleep, Object. wait, Thread. join, Lock. tryLock and Condition. the timing version of await.

Terminated thread:

  1) The thread naturally dies because the run method Exits normally.

2) The run method is terminated due to an uncaptured exception and an unexpected death occurs.

 

Conversions between thread states:

           

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.