作者:
可爱猪猪
-帅锅一枚
作者的网名很阔爱,如果喜欢本文章一定要点 喜欢 或者 打赏,拜托~
作者一直在进步,需要你们的支持和鼓励,谢谢!
人生理想:在程序猿界混出点名堂!
A thread state. A thread can be in one of the following states:
NEW
A thread that has not yet started is in this state.
RUNNABLE
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.
如下图:
Java线程的状态.png
是什么导致会出现这六种状态,以及六种状态是如何切换的,如下图:
Java 线程状态变迁.png
为什么线程是RUNABLE而不是RUNNING呢?
个人理解:因为线程执行的任务跟JVM和操作系统有关,比如JVM可能在执行垃圾回收STOP THE WORLD,因此任务会暂停或者操作系统上多个线程资源抢占,可能任务并没有抢到时间片,因此线程也没有在运行,因此Runnable状态的命名还是比较准确。
网友评论