假设我有以下情况:

final int index = 10;
Phone phone = phoneList.get(index);
synchronized(phone)
{
   //some code runs here
}

因此,当phone对象(通过phoneList.get()方法获得)被锁定时,另一个线程可以执行该方法:
phoneList.remove(index);

并在给定索引处将电话对象设为空?

最佳答案

是。为什么不?

但是,phone仍指向同一对象。即该对象已从列表中删除,但jvm仍对其进行引用。

09-16 17:54