Java线程状态中BLOCKED和WAITING的区别
来源:互联网 发布:matlab 随机矩阵 编辑:程序博客网 时间:2024/04/29 21:29
Java线程状态中BLOCKED和WAITING的区别
>java -versionjava version "1.6.0_43"Java(TM) SE Runtime Environment (build 1.6.0_43-b01)Java HotSpot(TM) 64-Bit Server VM (build 20.14-b01, mixed mode)
源代码说的很详细了
public enum State { /** * Thread state for a thread which has not yet started. */ NEW, /** * Thread state for a runnable thread. A thread in the runnable * state is executing in the Java virtual machine but it may * be waiting for other resources from the operating system * such as processor. */ RUNNABLE, /** * Thread state for a thread blocked waiting for a monitor lock. * A thread in the blocked state is waiting for a monitor lock * to enter a synchronized block/method or * reenter a synchronized block/method after calling * {@link Object#wait() Object.wait}. */ BLOCKED, /** * Thread state for a waiting thread. * A thread is in the waiting state due to calling one of the * following methods: * <ul> * <li>{@link Object#wait() Object.wait} with no timeout</li> * <li>{@link #join() Thread.join} with no timeout</li> * <li>{@link LockSupport#park() LockSupport.park}</li> * </ul> * * <p>A thread in the waiting state is waiting for another thread to * perform a particular action. * * For example, a thread that has called <tt>Object.wait()</tt> * on an object is waiting for another thread to call * <tt>Object.notify()</tt> or <tt>Object.notifyAll()</tt> on * that object. A thread that has called <tt>Thread.join()</tt> * is waiting for a specified thread to terminate. */ WAITING, /** * Thread state for a waiting thread with a specified waiting time. * A thread is in the timed waiting state due to calling one of * the following methods with a specified positive waiting time: * <ul> * <li>{@link #sleep Thread.sleep}</li> * <li>{@link Object#wait(long) Object.wait} with timeout</li> * <li>{@link #join(long) Thread.join} with timeout</li> * <li>{@link LockSupport#parkNanos LockSupport.parkNanos}</li> * <li>{@link LockSupport#parkUntil LockSupport.parkUntil}</li> * </ul> */ TIMED_WAITING, /** * Thread state for a terminated thread. * The thread has completed execution. */ TERMINATED; }
总结一下:
- Thread如果是在等待获取锁,此时Thread的状态就是Blocked;
- 其他调用Object.wait,Thread.join,LockSupport.park等都是WAITING或者TIMED_WAITING状态
0 0
- Java线程状态中BLOCKED和WAITING的区别
- Java线程状态中BLOCKED和WAITING有什么区别?
- java——线程生命周期waiting状态和blocked状态的区别
- java线程中BLOCKED和WAITING有什么区别?
- java线程waiting与blocked的区别
- 线程状态,BLOCKED和WAITING有什么区别
- Java Thread BLOCKED和WAITING两种状态的区别(英)
- Java多线程编程7--拾遗增补--线程的状态(new,runnable,terminated,timed_waiting,waiting,blocked)
- Jstack线程状态BLOCKED/TIMED_WAITING/WAITING解释
- 线程状态的区别 blocked waitting ,join 详解
- Java 线程状态之 WAITING
- Java线程 Block和Waiting的异同
- java 线程 / 线程池的run 方法内Exception ,线程遇到Exception 则死,线程池中线程A遇到Exception 则线程A 变成 WAITING状态,仍能接受调度
- Java中线程的状态
- java中线程的状态
- java中进程和线程的区别
- java中进程和线程的区别
- RAC 监听的BLOCKED状态
- android 判断有线耳机、蓝牙耳机连接
- Windows程序设计Day 5
- opencv全景拼接源码解读与修改。
- LeetCode题解(Week 3):206. Reverse Linked List
- HTTP学习之路
- Java线程状态中BLOCKED和WAITING的区别
- 关于PHP获取私有属性(调用阿里云sdk,返回带私有属性的对象)
- 推荐!手把手教你使用Git
- java设计模式(3)观察者模式
- 项目中当页面修改时自动保存到日志
- css3弹性盒模型(Flexbox)
- zoj 2104 出现次数最多的字符串 两种姿势
- Http协议与TCP协议简单理解
- ScrollView嵌套ListView滚动冲突的解决方案