先来一波官方的解释 A thread state. A thread can be in one of the following states:
NEWA thread that has not yet started is in this state. 创建了但是没有start
RUNNABLEA thread executing in the Java virtual machine is in this state. 可运行的(不是正在运行)
BLOCKEDA thread that is blocked waiting for a monitor lock is in this state. 被阻塞等到锁(被synchronized 修饰)
WAITINGA thread that is waiting indefinitely for another thread to perform a particular action is in this state. 等待另外一个线程的消息.
TIMED_WAITINGA thread that is waiting for another thread to perform an action for up to a specified waiting time is in this state. 时间等待
TERMINATEDA thread that has exited is in this state. 退出
先看图的左侧.是线程状态的主轴线.
Created with Raphaël 2.2.0 NEW RUNNABLE TERMINATED再来看右侧
Created with Raphaël 2.2.0 BLOCKED WAITING TIME_WAITING BLOCKD 和RUNNABLE之间的转换 获取了monitor锁 进入到被synchronized修饰的方法或者代码块 BLOCKED RUNNABLE WAITING 和RUNNABLE之间的转换 Object.wait Thread.join LockSuper.park Object.notify Object.notifyAll LockSuper.unpark RUNNABLE WAITING-TIME_WAITING 和RUNNABLE之间的转换
Thread.sleep Object.wait Thread.join Waiting time coming Object.notify Object.notifyAll RUNNABLE TIME_WAITING