我正在开发一个程序,其中有多个线程访问存储在类Problem
中的Map。
对于“值”,此映射包含一个对象(Slot
),该对象包含名称和List
实例的Car
。
所以,我的问题是:
由于通过不同线程访问的第一个映射是线程安全的,因此我需要Slot
内的列表的线程安全列表还是使用ArrayList
的安全列表?
请注意,Car
是AtomicReference
,是我使用compareAndSet()
的关键区域。
public class Problem {
ConcurrentSkipListMap<Integer, Slot> slots;
//...
}
public class Slot {
private String name;
List<AtomicReference<Car>> cars; // does this need to be a thread safe list?
//...
}
public class Car {
//...
}
显示问题的简单图表:
谢谢。