可能这对我来说很愚蠢,但我查看了源代码ConcurrentHashMap
,我无法lock()
在该类的任何地方看到该方法的定义,但我可以看到该方法在多个场合被调用。在 Eclipse 中,当我说打开声明时lock()
,它会显示类ReentrantLock.lock()
,所以我很困惑这是如何工作的?ReentrantLock
lock() 方法调用的对象引用在哪里?
V readValueUnderLock(HashEntry<K,V> e) {
lock(); // where is this method defined in CHM ?
try {
return e.value;
} finally {
unlock();
}
}