为什么即使我们使用同步方法并因此获得对 Helper 对象的锁定,这段代码也不是线程安全的?
class ListHelper <E> {
public List<E> list = Collections.synchronizedList(new ArrayList<E>());
public synchronized boolean putIfAbsent(E x) {
boolean absent = !list.contains(x);
if (absent)
list.add(x);
return absent;
}
}