ReentrantLock 实现原理
ReentrantLock 实现原理
锁类型
默认是非公平锁,在创建时可以指定锁的类型
public ReentrantLock() {
sync = new NonfairSync();
}
/**
* Creates an instance of {@code ReentrantLock} with the
* given fairness policy.
*
* @param fair {@code true} if this lock should use a fair ordering policy
*/
public ReentrantLock(boolean fair) {
sync = fair ? new FairSync() : new NonfairSync();
}公平锁
非公平锁
写入队列
挂起线程
释放锁
总结
Last updated
Was this helpful?
