【发布时间】:2013-02-16 22:09:02
【问题描述】:
在 Java 文档中它说同步的集合必须在迭代中再次手动同步。这是为什么?由于返回的集合已经同步。不太明白为什么会这样。谢谢你。
Collection c = Collections.synchronizedCollection(myCollection);
...
synchronized(c) {
Iterator i = c.iterator(); // Must be in the synchronized block
while (i.hasNext())
foo(i.next());
}
【问题讨论】:
标签: java multithreading synchronized