As a number of people have noted and encountered HashMap.put
can go into an infinite execution loop when used concurrently (see GRIZZLY-1207, JGRP-525, possibly HHH-6414, and this SO answer).
HashMap
is clearly documented as not thread safe. Obviously, the correct fix is to use a thread-safe implementation of Map
, ConncurrentHashMap
in particular. I'm more curious about the concurrent timing that causes the infinite loop. I encountered this loop recently with a Java 7 JRE and would like to understand the exact causes. For example, is this caused by multiple puts at the same time?
A look inside HashMap.put shows that HashMap.Entry
contains a link to the next node (in the bucket?). I assume these links are getting corrupting to contain circular references, which is causing the infinite loop. However, I still don't understand exactly how that corruption is occurring.