本文介绍了独占锁定ConcurrentHashMap的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道不可能锁定一个ConcurrentHashMap进行独占访问。
然而,我找不到为什么。
I know that it is not possible to lock a ConcurrentHashMap for exclusive access.However, I cannot find why.
这是因为段的构成CHM不是由api暴露?
假定如果是,客户端代码可以执行手动锁定?
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?
干杯
推荐答案
简单 - 因为它不是真的。每个线程的单实例如何?如何同步方法或同步块?信号量访问逻辑如何?
Simple - because it is not true. How about single instance per thread? How about synchronized methods or synchronized blocks? How about semaphore access logic?
这篇关于独占锁定ConcurrentHashMap的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!