Consider the following code and assume that list is an synchronized List.
List list = Collections.synchronizedList(new ArrayList());
if(!list.contains(element)){
list.add(element)
}
I know that above code fragment needs to be synchronized externally (guarded by a lock) to make it completely thread safe .Where does the race condition come in here ?
Imagine you have two threads
Of course the simple solution is to use a Set. e.g.