果冻的猿宇宙 – Just Do IT,放胆做挨踢 |
您所在的位置:网站首页 › 果冻的状态 › 果冻的猿宇宙 – Just Do IT,放胆做挨踢 |
Java 线程有 6 种状态. 在某个给定时间点上, 一个线程只能处于这 6 种状态中的一种. 线程状态的枚举: Thread.State这 6 种状态被明确地定义在 Thread 类的一个内部枚举类 Thread.State 中: 它们是: 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.注: 以上内容直接来自 State 类中的 Javadoc, 只对状态进行了翻译, 具体的描述后面再分析. 它上面还有个注解 @since 1.5, 暗示了在 JDK1.5 时引入了这些定义. 因此, 说有 6 种线程状态是对 1.5 及以后版本而言. Thread 类中有一个方法 getState, 返回的就是这里定义的状态. 可用于监控工具分析线程状态, 不作同步工具使用. 继续阅读 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |