ReentrantReadWriteLock.ReadLock
ReentrantReadWriteLock.WriteLock
对于上述两个类,我是否像这样调用 lock
try {
readLock.tryLock(10, TimeUnit.SECONDS)
[...]
} finally {
readLock.unlock();
}
或者
readLock.tryLock(10, TimeUnit.SECONDS)
try {
[...]
} finally {
readLock.unlock();
}
哪个更安全,同样适用于lock()
方法与tryLock()
方法?