Is it safe to perform foreach, add, remove, size operations in different threads with the next set?
private final Set<MyObject> myConcurrentHashSet = ConcurrentHashMap.newKeySet();
Yes, the keySet view is thread safe, the newKeySet in java >=8 is equivalent to this java 7 form:
for java <= 7
ConcurrentHashMap c = ...; Set threadSafeSet = c.keySet();
for java >=8
Set threadSafeSet = ConcurrentHashMap.newKeySet();