Exclusively Locking ConcurrentHashMap

三世轮回 提交于 2019-12-24 12:34:29

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!