标签:java com 使用 UI 方法 模板 bst unlock dex
api:lock(), unlock()....
同步器的设计是基于模板方法模式的,也就是说,使用者需要继承同步器并重写指定的方法,随后将同步器组合在自定义同步组件的实现 中, 并调用同步器提供的模板方法,而这些模板方法将会调用使用者重写的方法。
可重写的方法:
protected boolean tryAcquire(int arg)
protected boolean tryRelease(int arg)
protected int tryAcquireShared(int arg)
protected boolean tryReleaseShared(int arg)
protected boolean isHeldExclusively()
在重写的方法中,需要对同步进行更改时,可以使用同步器提供的三个方法来安全地改变同步状态:
getState()
setState()
compareAndSetState()
重入锁
标签:java com 使用 UI 方法 模板 bst unlock dex
原文地址:http://www.cnblogs.com/zhouj-happy/p/6483817.html