公平锁的初始化
2020-03-19 本文已影响0人
kele2018
1、默认实例化非公平锁
public ReentrantLock() {
sync = new NonfairSync();
}
2、实例化公平锁(需要传参)
public ReentrantLock(boolean fair) {
sync = fair ? new FairSync() : new NonfairSync();
}
public ReentrantLock() {
sync = new NonfairSync();
}
public ReentrantLock(boolean fair) {
sync = fair ? new FairSync() : new NonfairSync();
}