The easiest way to get a synchronized version of java.util.Set would be using Collections.synchronizedSet () as follows:
Set mySyncSet = Collections.synchronizedSet(new HashSet());
The Java API talks about this new object, which:
It is imperative that the user manually synchronizes the returned set when iterating over it
My question is: if I create a copy of this Install using the copy constructor as follows:
Set mySetCopy = new HashMap(mySyncSet);
Kill it thread safe? (is not a HashMap constructor using iteration to get Install members?) or do I need to manually synchronize the operation as follows:
Set mySetCopy; synchronized(mySyncSet) { mySetCopy = new HashMap(mySyncSet); }
source share