我在dos.oracle.com找到了这个
public static List synchronizedList(List list)
Returns a synchronized (thread-safe) list backed by the specified
list. In order to guarantee serial access, it is critical that all
access to the backing list is accomplished through the returned list.
It is imperative that the user manually synchronize on the returned
list when iterating over it:
List list = Collections.synchronizedList(new ArrayList());
...
synchronized(list) {
Iterator i = list.iterator(); // Must be in synchronized block
while (i.hasNext())
foo(i.next());
}
我的问题是:为什么我必须同步列表来迭代它,如果Collections.synchronizedList();应该返回一个已经同步的列表?
我只是在两个线程中加入列表:一个线程只是添加,另一个线程获取和删除.您推荐哪些其他课程用于此场景?
谢谢阅读.