Let's say I could have thousands of objects of a certain type, and in each object there is one field for a List or set, but this list or set needs to be concurrent. A concurrent hashmap in each of hundreds or thousands of objects seems like overkill (or is it?). I also needs an atomic put-if-absent operation in each list/set. Is a ConcurrentHashMap overkill or too expensive? Is there a more lightweight alternative? I'd prefer not to do a synchronized set or list...
There is concurrent CopyOnWriteArraySet which is good only for sets which rarely change.
Another option is to make a Set from ConcurrentHashMap
Set<Object> set1 = Collections.newSetFromMap(new ConcurrentHashMap<Object, Boolean>());