Home Java JavaBase What are the several states of java threads?

What are the several states of java threads?

May 14, 2020 pm 03:53 PM
java thread

What are the several states of java threads?

In the running cycle of the java thread, there are the following states:

1, NEW

This state is It means that the thread has just been created and has not been started yet.

2. RUNNABLE

means that the thread is running normally. Of course, there may be some time-consuming calculations/IO waiting operations/CPU time slice switching, etc. This The waiting that occurs in the state is generally other system resources, not locks, Sleep, etc.

(Recommended video tutorial: java video)

3. BLOCKED

In this state, multiple threads are running There are scenarios of synchronous operations, such as waiting for the execution release of another thread's synchronized block, or someone else calling the wait() method in a reentrant synchronized block, which means that the thread is waiting to enter the critical section.

4. WAITING

This state means that after the thread owns a certain lock, it calls its wait method and waits for other threads/lock owners to call notify. / notifyAll once, the thread can continue to the next operation.

Here we need to distinguish the difference between BLOCKED and WATING. One is waiting outside the critical point to enter, and the other is waiting inside the understanding point to wait for others to notify. When a thread calls the join method to join another thread, it will also Enters the WAITING state and waits for the execution of the thread joined by it to end.

5. TIMED_WAITING

This state is limited (time limit) WAITING, which generally occurs when wait(long), join(long), etc. are called. After another thread sleeps, it will also enter the TIMED_WAITING state.

6. TERMINATED

In this state, it means that the run method of the thread has been executed, which is basically equivalent to death (if the thread is held persistently at that time, may not be recycled).

Recommended tutorial: java entry program

The above is the detailed content of What are the several states of java threads?. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Square Root in Java Square Root in Java Aug 30, 2024 pm 04:26 PM

Square Root in Java

Perfect Number in Java Perfect Number in Java Aug 30, 2024 pm 04:28 PM

Perfect Number in Java

Random Number Generator in Java Random Number Generator in Java Aug 30, 2024 pm 04:27 PM

Random Number Generator in Java

Armstrong Number in Java Armstrong Number in Java Aug 30, 2024 pm 04:26 PM

Armstrong Number in Java

Weka in Java Weka in Java Aug 30, 2024 pm 04:28 PM

Weka in Java

Smith Number in Java Smith Number in Java Aug 30, 2024 pm 04:28 PM

Smith Number in Java

Java Spring Interview Questions Java Spring Interview Questions Aug 30, 2024 pm 04:29 PM

Java Spring Interview Questions

Break or return from Java 8 stream forEach? Break or return from Java 8 stream forEach? Feb 07, 2025 pm 12:09 PM

Break or return from Java 8 stream forEach?

See all articles