Search code examples
javaconcurrencyjvmfalse-sharing

Dose Segment in ConcurrentHashMap has false sharing problems?


java.util.concurrent.ConcurrentHashMap uses a Segment array as Mutexand Segment Object is small than cache line.

Does this lead to false sharing?


Solution

  • While the Segments are small, this is not where the multi-threading support happens. It extends ReentrantLock which uses a Sync object which extends AbstractQueuedSchronizer which uses Node objects. All these objects would be copied as a group and are likely to be spaced out reasonably well. This would depend on the implementation of the GC as to how this is done, but for Hotspot it is copied in reverse order of discovery (i.e. a deep copy) so it is likely this will be fine.