Thread State of Java

Source: Internet
Author: User

There are 6 states of Java threads:

1.New (new), when you create a new thread with new, the thread is in a nascent state, and the new state makes some preparation for the run of the thread, but it is not yet ready to run.

2.Runnable (can be run), calling the thread's start method to make the thread in a running state. The operational state does not necessarily mean that the thread is running, but that it has a running condition, it may be running, or it may not be running, depending on the thread scheduling control.

3.Blocked (blocked), when a thread attempts to acquire an internal object lock, the object lock is held by another thread, and the thread enters a blocking state.

4.Waiting (Wait) when the Object.wait method, Thread.Join method, lock or condition in the Java.util.concurrent library are called, the thread goes into a wait state.

5.Timed Waiting (wait on time), the condition that enters the state and the condition to enter the wait state are the same, but this state can wake up after a specified time, so it is different from the waiting state.

6.Terminated (terminated), Java does not have a way to directly terminate a thread (stop has been declared obsolete is not allowed to use, the Interrrupt method is only a request interrupt, not necessarily can interrupt a thread), Therefore, the thread will enter the terminating state only if the program ends naturally or throws an exception that is not caught.

Thread State of Java

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.