[concurrency-interest] ConcurrentMap consistency requirements confusion

Chris Dennis cdennis at terracottatech.com
Thu Dec 8 16:42:53 EST 2011

Hi All,

This question may be born out of an inability to parse the English language, fully understand the JVM, me being a pedant, or it may have an interesting story behind it.  I wondered if someone on this list could enlighten me regardless.

The javadoc for ConcurrentMap (the interface *not* CHM) states:

"Memory consistency effects: As with other concurrent collections, actions in a thread prior to placing an object into a ConcurrentMap as a key or value happen-before actions subsequent to the access or removal of that object from the ConcurrentMap in another thread."

This seems to imply to me by saying "...actions in a thread prior to placing an..." rather than "...actions in a thread prior to and including the action of placing an..." that there is no requirement in a ConcurrentMap for there to be a happens-before relationship between the action of putting the mapping in to the map and subsequently attempting to read that mapping.

Does that mean that a valid ConcurrentMap implementation could cause the following method to never terminate?

  public static void foreverRead(final ConcurrentMap<Boolean, Boolean> map) throws InterruptedException {
    Thread t = new Thread() {
      public void run() {
        while (!map.containsKey(Boolean.TRUE));
    map.put(Boolean.TRUE, Boolean.TRUE);

CHM obviously does terminate here due to it's implementation, as I imagine most (if not all) possible implementations would.

Thanks in advance for any information or education.  


More information about the Concurrency-interest mailing list