I have a Map
which is read by multiple threads but which is (from time to time) cleared and rebuilt by another thread.
I have surrounded all the access to this map with
readWriteLock.readLock().lock()
try {
... access myMap here...
} finally {
readWriteLock.readLock().unlock()
}
... or the writeLock()
equivalents, depending on the type of access.
My question is... will the ReadWriteLock
ensure the updates to myMap
are visible to the other threads (since they must wait until after the unlock()
is called by the writing thread? Or, do I also need to make myMap
a concurrent map, like ConcurrentHashMap
?
I will probably do that, just to be safe, but I'd like to understand better.