In a multi-thread module, I don’t care whether it is thread-safely writing over a java.util.Collection (e.g. java.util.Set) object. What it does is removing some independent elements by multiple threads, which may perform removal on the same element at the same time. Then, what happens? That element is removed, or any exception is thrown?
Kejia
It is even possible that an ConcurrentModificationException is thrown, when you remove different objects. That depends on the implementation of the Set you are using: The remove() method may iterate over the set. Or worse: It may modifies some other internal variables and leave the set in an inconsistent state without throwing any exception.
There is a really easy solution:
You still need to pay attention if you want to iterate over it, as described in the apidoc: http://download.oracle.com/javase/6/docs/api/java/util/Collections.html#synchronizedSet%28java.util.Set%29 but all the other methods (including remove) are fine.