java.lang.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.
使用vm监视器对sleep、wait、block监视的状态分别为休眠、等待、监视
sleep语义:我完成了我的时间片,在我休眠的这段时间不要给我分配时间片了
wait语义:我完成了我的时间片,在其他人唤醒我之间不要给我分配时间片了
ReentrantLock的同步器实现中,使用Unsafe.park()和Unsafe.unpark()阻塞和唤醒线程
同wait/notify在实现上有什么区别?
参考:
http://www.logicaltrinkets.com/wordpress/?p=153
http://www.docjar.com/docs/api/sun/misc/Unsafe.html#unpark(Object)
http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/Thread.State.html
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.
使用vm监视器对sleep、wait、block监视的状态分别为休眠、等待、监视
sleep语义:我完成了我的时间片,在我休眠的这段时间不要给我分配时间片了
wait语义:我完成了我的时间片,在其他人唤醒我之间不要给我分配时间片了
ReentrantLock的同步器实现中,使用Unsafe.park()和Unsafe.unpark()阻塞和唤醒线程
同wait/notify在实现上有什么区别?
参考:
http://www.logicaltrinkets.com/wordpress/?p=153
http://www.docjar.com/docs/api/sun/misc/Unsafe.html#unpark(Object)
http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/Thread.State.html