… While locking can prevent iterators from throwing ConcurrentMofdificationException, You have to remember to use locking everywhere a shared collection might be iterated. This is trickier than it sounds … Brian Goetz p.83-84 Question: The following code could throw ConcurrentMofdificationException, even though add() is synchronized, why? public class HiddenIterator { private final Set set = [...]
Posted by Alexander Zagniotov in: brainteaser, design patterns, threads on Sep 7th, 2008 18:05
