Posts

Showing posts with the label collections

Block read operation of ConcurrentHashMap in multithreaded environment

Block read operation of ConcurrentHashMap in multithreaded environment I have a ConcurrentHashMap. When thread t1 will do a write operation on it then I want thread t2 cannot do any read operation on it. The read operation should then be blocked. How will I achieve this? I cannot use HashMap and synchronize it. Then can you synchronize on the ConcurrentHashMap itself? – user7 Jun 30 at 5:31 There is no real point in using a ConcurrentHashMap then. A simple HashMap is sufficient. Synchronize the accesses using a ReadWriteLock. docs.oracle.com/javase/8/docs/api/java/util/concurrent/locks/… – JB Nizet Jun 30 at 5:31 Why use a ConcurremtHashMap if...