BYTECODES

Java线程状态

Java 线程有6种状态。在某个给定时间点上,一个线程只能处于这6种状态中的一种。它们分别是:

NEW (新建)

一个尚未启动的线程处于这一状态。(A thread that has not yet started is in this state.)

RUNNABLE (运行中)

一个正在 Java 虚拟机中执行的线程处于这一状态。(A thread executing in the Java virtual machine is in this state.)

BLOCKED (阻塞)

一个正在阻塞等待一个监视器锁的线程处于这一状态。(A thread that is blocked waiting for a monitor lock is in this state.)

WAITING (等待)

一个正在无限期等待另一个线程执行一个特别的动作的线程处于这一状态。(A thread that is waiting indefinitely for another thread to perform a particular action is in this state.)

TIMED_WAITING (计时等待)

一个正在限时等待另一个线程执行一个动作的线程处于这一状态。(A thread that is waiting for another thread to perform an action for up to a specified waiting time is in this state.)

TERMINATED (终止)

一个已经退出的线程处于这一状态。(A thread that has exited is in this state.)

如何查看当前程序中线程状态

可以使用jstack,比如

jstack 1460 > stack.out 

1460是java进程的PID,然后我们打开stack.out文件,可以看到类似下面的信息

![2023-04-14T07:50:57.png][1]


[1]: https://cxyll.com/usr/uploads/2023/04/4107014085.png