Java Thread State Analysis

Source: Internet
Author: User

The thread state is identified in Java by an internal enumeration of the thread.

NEW---->runnable---->blocked---->waiting---->timed_waiting---->terminated

1. Creation status (Thread.State.NEW)

If you just create a thread and do not start it (start), the thread state is created.

For example: Thread thread1 = new Thread ();

The thread in the creation State has not yet obtained the resources it deserves, so this is an empty thread. The system will assign resources to a thread only after it has been started.

2. Operational status (Thread.State.RUNNABLE)

Start a thread by calling T.start () to put the thread into a running (Thread.State.RUNNABLE) state. The thread in that State enters the ready queue, and when the thread gets the CPU the time slice starts to run.

3. Blocking State ( thread.state. BLOCKED )

The thread state of one of the threads that is blocked and is waiting for a monitor lock. A thread in a blocked state is waiting for a monitor lock to enter a synchronized block/method, or to enter the synchronized block/method again after calling Object.wait.

4. Wait State ( Thread.State.WAITING ,timed_waiting)

The thread state of a waiting thread. A thread is waiting because it calls one of the following methods:

Object.wait with no time-out value

Thread.Join with no time-out value

Locksupport.park

A thread that is waiting waits for another thread to perform a specific operation. For example, a thread that has already called object.wait () on an object is waiting for another thread to call Object.notify () or Object.notifyall () on that object. A thread that has already called thread.join () is waiting for the specified thread to terminate.

Timed_waiting the thread state of a waiting thread with a specified wait time. A thread is in a timed wait state because it calls one of the following methods with the specified positive wait time:

Thread.Sleep

Object.wait with time-out value

Thread.Join with time-out value

Locksupport.parknanos

Locksupport.parkuntil

5, End state (thread.state. TERMINATED)

This article is from the "program Ape's Cultivation" blog, please be sure to keep this source http://zhoum1118.blog.51cto.com/10054110/1660101

Java Thread State Analysis

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.