ReadWriteLockApplicable to situations where there are far more reading threads than writing threads, and generally reading will be blocked when there is writing - in this case, it is even worse than a normal lock.
From a simplified programming model point of view, ConcurrentHashMap should be used, and it can be used to directly generate instances of Map. With the lock mechanism, you need to manage the status of these locks yourself.
From a performance point of view, ConcurrentHashMap should also be used, because it has internally optimized the reading and writing operations in blocks. In most cases, reading and writing can be performed at the same time. It's hard to be more efficient on your own. Specific details can be found in this article
should be used
ConcurrentHashMap
.ReadWriteLock
Applicable to situations where there are far more reading threads than writing threads, and generally reading will be blocked when there is writing - in this case, it is even worse than a normal lock.From a simplified programming model point of view,
ConcurrentHashMap
should be used, and it can be used to directly generate instances ofMap
. With the lock mechanism, you need to manage the status of these locks yourself.From a performance point of view,
ConcurrentHashMap
should also be used, because it has internally optimized the reading and writing operations in blocks. In most cases, reading and writing can be performed at the same time. It's hard to be more efficient on your own. Specific details can be found in this article