[concurrency-interest] a special detaila about ConcurrentHashMapV8

Doug Lea dl at cs.oswego.edu
Tue Jul 31 08:11:58 EDT 2012


On 07/31/12 01:43, ma zhen wrote:
> I notice a very small change from ConcurrentHashMap to ConcurrentHashMapV8
>
> ConcurrentHashMap
> static final class HashEntry<K,V> {
>          final K key;
>          final int hash;
>          volatile V value;
>          final HashEntry<K,V> next;
>
> ConcurrentHashMapV8
> static class Node {
>          volatile int hash;
>          final Object key;
>          volatile Object val;
>          volatile Node next;
>
>
> In ConcurrentHashMap, Entry's 'next' field is final, which means the
> relationship among entries is read-only after it have been created.
> In contrast, 'next' field defined in ConcurrentHashMapV8 is volatile, so the
> structure of nodes can be modified.
> I think read-only structure can provide more concurrency because it need not add
> lock when go through the enties, although this way involves many object copy.
>

Use of the more complicated volatile-next-based scheme is needed to
support new/upcoming functionality including partitioned
access. There is still no copying involved except in some
cases during resizing, but there are more internal constraints
about access, described in the internal documentation.

-Doug



More information about the Concurrency-interest mailing list