Hello. Such a problem - as a container I use MultiValueMap from commons-coolection. The key is String, Value is ArrayList. Several threads simultaneously access my Map, which read the value (ArrayList), take an elimination from it, after which this element is removed from this ArrayList. The problem is that I don't know how to synchronize it correctly. If I synchronize operations to remove an item from an ArrayList in the same way:
synchronize(myMap) { Collection c = myMap.getCollection(key);// Возвращается value - ArrayList c.get(randomIndex); c.remove(randomIndex); // Удаление элемента из листа }
Does this mean that read-delete operations for my ArrayList are thread-safe? After all, the sheet itself is not synchronized, and as you can see from the example, for synchronization, I use the Map object and not the List object.