Ensure to get all values of `ConcurrentHashMap` when iterating over it while other threads put elements
问题 I have a ConcurrentHashMap that gets filled with put by 8 different Threads. One of the 8 Threads tries to read with a forEach consumer. My problem is, that the ConcurrentHashMap only has 5-7 entries. map.put(myContent); ... map.forEach(element -> ... do something); If I add a map.size() it for some reason shows all 8 entries map.put(myContent); map.size(); ... map.forEach(element -> ... do something); Going through the ConcurrentHashMap docs shows that it is not really thread-safe to iterate