问题
I know that it is not possible to lock a ConcurrentHashMap for exclusive access. However, I cannot find why.
Is it because the "Segments" which constitue CHM aren't exposed by the api? Presumably if they were, the client code could perform a "hand-over-hand" locking?
Cheers
回答1:
I know that it is not possible to lock a ConcurrentHashMap for exclusive access. However, I cannot find why.
Simple - because it is not true. How about single instance per thread? How about synchronized methods or synchronized blocks? How about semaphore access logic?
回答2:
Exclusive lock of concurrenthashMap can be gained using synchronizer in JAVA like Synchronizationblock, locking API
来源:https://stackoverflow.com/questions/22004059/exclusively-locking-concurrenthashmap