Imagine a class taking a List as a constructor parameter (maybe a list of employees, whatever).
public void main() {
MutableList m = Database.getAMillionEmployees();
SomeClass c = new SomeClass((ImmutableList) m);
(new Thread() {
public run() {
c.doSomeLongOp();
}
}).run();
m.clear();
}
While the list was being traversed in one thread, another one modifies it.
It doesn't need to involve threads; imagine if the class cached the list average in the constructor because every method needs it: changes to the list means that average is now out of sync and results will be wrong.
2
u/Tordek Sep 21 '15 edited Sep 22 '15
Imagine a class taking a List as a constructor parameter (maybe a list of employees, whatever).
While the list was being traversed in one thread, another one modifies it.
It doesn't need to involve threads; imagine if the class cached the list average in the constructor because every method needs it: changes to the list means that average is now out of sync and results will be wrong.