?
ReentrantReadWriteLock读写锁的使用2(二)
try {
// Recheck state because another thread might have
// acquired write lock and changed state before we did.
if (!cacheva lid) {
data = ...
cacheva lid = true;
}
// Downgrade by acquiring read lock before releasing write lock
rwl.readLock().lock();
} finally {
rwl.writeLock().unlock(); // Unlock write, still hold read
}
}
try {
use(data);
} finally {
rwl.readLock().unlock();
}
}
}
?
?