线程有哪几种状态?
查看java.lang.Thread类的源码可以发现:
<ul>
* <li>{@link #NEW}<br>
* A thread that has not yet started is in this state.
* </li>
* <li>{@link #RUNNABLE}<br>
* A thread executing in the Java virtual machine is in this state.
* </li>
* <li>{@link #BLOCKED}<br>
* A thread that is blocked waiting for a monitor lock
* is in this state.
* </li>
* <li>{@link #WAITING}<br>
* A thread that is waiting indefinitely for another thread to
* perform a particular action is in this state.
* </li>
* <li>{@link #TIMED_WAITING}<br>
* A thread that is waiting for another thread to perform an action
* for up to a specified waiting time is in this state.
* </li>
* <li>{@link #TERMINATED}<br>
* A thread that has exited is in this state.
* </li>
* </ul>
NEW 初始状态没有调用start()
RUNNABLE 运行状态
BLOCKED 阻塞
一、等待阻塞 运行的线程执行了wait()
二、同步阻塞synchorized
三、其他阻塞 sleep join
TIMED_WAITING时间等待
TERMINATED 终止
本篇结。