首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

非拥塞算法-ReentrantLock代码剖析之ReentrantLock.lock

2012-11-14 
非阻塞算法-ReentrantLock代码剖析之ReentrantLock.lockReentrantLock是java.util.concurrent.locks中的一

非阻塞算法-ReentrantLock代码剖析之ReentrantLock.lock

ReentrantLock是java.util.concurrent.locks中的一个可重入锁类。在高竞争条件下有更好的性能,且可以中断。深入剖析ReentrantLock的源码有助于我们了解线程调度,锁实现,中断,信号触发等底层机制,实现更好的并发程序。

以下代码出自JDK1.6

先来看ReentrantLock最常用的代码lock

?非拥塞算法-ReentrantLock代码剖析之ReentrantLock.lock?非拥塞算法-ReentrantLock代码剖析之ReentrantLock.lock

在上图的类层次中,最核心的类当属 AbstractQueuedSynchronizer ,最重要的两个数据成员当前锁状态和等待链表都是由它来实现的。

?非拥塞算法-ReentrantLock代码剖析之ReentrantLock.lock?非拥塞算法-ReentrantLock代码剖析之ReentrantLock.lock?非拥塞算法-ReentrantLock代码剖析之ReentrantLock.lock?非拥塞算法-ReentrantLock代码剖析之ReentrantLock.lock?非拥塞算法-ReentrantLock代码剖析之ReentrantLock.lock?非拥塞算法-ReentrantLock代码剖析之ReentrantLock.lock?非拥塞算法-ReentrantLock代码剖析之ReentrantLock.lock?非拥塞算法-ReentrantLock代码剖析之ReentrantLock.lock?非拥塞算法-ReentrantLock代码剖析之ReentrantLock.lock?非拥塞算法-ReentrantLock代码剖析之ReentrantLock.lock?/** * Convenience method to park and then check if interrupted * * @return {@code true} if interrupted */ private final boolean parkAndCheckInterrupt() { LockSupport.park(this); return Thread.interrupted(); }



关于线程的更多知识可以参考:http://www.ibm.com/developerworks/cn/java/j-concurrent/

该文章为Agrael转帖,并在转帖的内容上做了一定的更改和注释,版权属于原作者拥有。红色字体为Agarel添加的注释。

热点排行