Home > Java > javaTutorial > There are several states of java threads

There are several states of java threads

(*-*)浩
Release: 2019-12-26 14:30:37
Original
3717 people have browsed it

There are several states of java threads

Thread is a dynamic execution process. It has a process from birth to death, with a total of five states:

New Thread (new Thread) ##Ready (runnable)

The thread has been started and is waiting to be assigned to the CPU time slice, which means that the thread is queuing in the ready queue waiting to get CPU resources. . For example: t1.start();

Running(running)

The thread has obtained the CPU resource and is executing the task (run() method). At this time, unless this thread automatically If the CPU resource is given up or a thread with a higher priority enters, the thread will run until the end.

Death(dead)

When the thread completes execution or is killed by other threads, the thread enters the death state. At this time, the thread cannot enter the ready state and wait for execution. .

Natural termination: Terminate after running the run() method normally

Abnormal termination: Call the stop() method to stop a thread from running

Blocked (blocked)

For some reason, the running thread gives up the CPU and suspends its own execution, that is, it enters a blocking state.

Sleeping: Use the sleep(long t) method to put the thread into sleep mode. A sleeping thread can enter the ready state after the specified time has elapsed.

Waiting: Call the wait() method. (Call the motivate() method to return to the ready state)

Blocked by another thread: call the suspend() method. (Call the resume() method to restore).

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

Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template