ReentrantLock
2022-05-20 16:50:06 0 举报
reentrantlock源码解析
作者其他创作
大纲/内容
ReentrantLock lock = new ReentrantLock()
FairSync
+ final void lock(): void+ protected final boolean tryAcquire(int acquries): boolean
public final boolean hasQueuedPredecessors() { // The correctness of this depends on head being initialized // before tail and on head.next being accurate if the current // thread is first in queue. Node t = tail; // Read fields in reverse initialization order Node h = head; Node s; return h != t && ((s = h.next) == null || s.thread != Thread.currentThread());}
final void lock() { acquire(1);}
extends
inner class
ReentrantLock
private final Sync
private final boolean parkAndCheckInterrupt() { LockSupport.park(this); return Thread.interrupted();}
sync.lock();
abstract class AbstractQueuedSynchronizerprotected boolean tryAcquire(int arg) { throw new UnsupportedOperationException();}
start
NonFairSync
+ final void lock(): void+ protected final boolean tryAcquire(int acquires):boolean
Sync
+ abstract void lock(): void+ final boolean nonfairTryAcquire(int acquires):boolean
protected final boolean tryAcquire(int acquires) { return nonfairTryAcquire(acquires);}
lock.lock()
0 条评论
下一页