четверг, 15 октября 2009 г.

Testing Race Conditions in Java

Can you spot the bug in the following piece of Java code?


/** Maintains a list of names. */
public class NameManager {
private List names = new ArrayList();
/** Stores a new list of names. This method is threadsafe. */
public void setNames(List newNames) {
synchronized (names) {
names = new ArrayList();
for (String name : newNames) {
names.add(name);
}
}
}


Продолжение:
http://google-opensource.blogspot.com/2009/10/testing-race-conditions-in-java.html

Комментариев нет:

Отправить комментарий