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();
}
本文标题:公平锁的初始化
本文链接:https://www.haomeiwen.com/subject/dpxlyhtx.html
网友评论