在毕老师的java基础源码 day19e中的"集合框架_4.txt"中,“给非同步的集合加锁”的代码中有一个小问题:
老毕的源码如下:
给非同步的集合加锁。
class MyCollections{
public static List synList(List list){
return new MyList(list);
}
private class MyList implements List{
private List list;
private static final Object lock = new Object();
MyList(List list){
this.list = list;
}
public boolean add(Object obj){
synchronized(lock)
{
return list.add(obj);
}
}
public boolean remove(Object obj){
synchronized(lock)
{
return list.remove(obj);
}
}
}
}
-----------------------------------------问题分析图如下---------------------------------------
|