无锁ConcurrentSkipListMap,以复杂对象作为包含列表的值

时间:2019-06-12 15:19:23

标签: java concurrency java.util.concurrent concurrentskiplistmap

我正在开发一个程序,其中有多个线程访问存储在类Problem中的Map。 对于“值”,此映射包含一个对象(Slot),该对象包含名称和List实例的Car

所以,我的问题是:

由于通过不同线程访问的第一个映射是线程安全的,因此我需要Slot内的列表的线程安全列表还是使用ArrayList的安全列表? 请注意,CarAtomicReference,是我使用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 {
            //...
        }

显示问题的简单图表:

enter image description here

谢谢。

0 个答案:

没有答案