I ran into some shady piece of code in which a HashSet is accessed and modified by several threads at the same time, and I wanted to know what effects this could have had, considering the Javadoc only explains the behavior is “non-deterministic” under concurrent, unsynchronized accesses.
Specifically, is it possible that a call to remove(element) returns true, but that the effects of the call are never ever seen by other threads (ie. contains(element) will always return true in other threads) ?
PS: Just to reassure you, I know this code is bad and I will replace the HashSet with an equivalent synchronized collection.
Accessing HashSet in multiple threads can.
Note: a simple replacement is to use