Home  >  Article  >  Java  >  What are the several states of java threads?

What are the several states of java threads?

王林
王林Original
2020-05-14 15:53:012598browse

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:
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