title: How to declare a volatile list within a concurrent hashmap?
body: <p>I have a variable:</p>
  
  <pre><code>ConcurrentHashMap&lt;String, List&lt;AnObjectType&gt;&gt; mapOfList;
  </code></pre>
  
  <p>The List as I understand is not thread safe. But I don't want to use Synchronized keyword as I actually want concurrent read access and synchronized write to the list and not blocking read and writes.</p>
  
  <p>So I would normally declare <code>Volatile</code> on the variable like so:</p>
  
  <pre><code>volatile List&lt;AnObjectType&gt; varName;
  </code></pre>
  
  <p>(Although in this case I think this referers to Volatile reference on the list, but what I want is for both the list reference and the content of the list to be volatile.)</p>
  
  <p>But how do I do that within a ConcurrentHashMap construct given that I don't declare the list as a variable anywhere but within a method?</p>
  
  <p>i.e. List is created within method:</p>
  
  <pre><code>if (!mapOfList.containsKey("ListA")) {
       List&lt;AnObjectType&gt; listA=new ArrayList&lt;AnObjectType&gt;();
       mapOfList.put("ListA", listA);
  }
  </code></pre>
  
  <p>and the list is accessed in another method within the same class:</p>
  
  <pre><code>List&lt;AnObjectType&gt; listA=mapOfList.get("ListA");
  if (listA!=null) {
       // Do something concurrent with listA.
  }
  </code></pre>
  
  <p>Sub Question: Would something like this work at all?</p>
  
  <p><code>ConcurrentHashMap&lt;String,List&lt;AtomicReference&lt;AnObjectType&gt;&gt;&gt;&gt;</code></p>
  
  <p>Elaboration on the list's operations:</p>
  
  <p>The list will be accessed via multiple threads reading almost constantly. Write access to the list will be triggered on certain conditions. So what I want is a concurrent access to the List's content with seldom write operations on the list's content that should be reflected by all reads after the write operation.</p>