Since both the garbage collector thread and the writer thread can try to modify the global list at the same time, some kind of locking mechanism also has to be used.
因为垃圾收集器线程和写入者线程可能同时尝试修改全局列表,所以同样也需要使用某种锁定机制。
2
It implements List and is thread-safe, but its iterators will not throw ConcurrentModificationException and do not require any additional locking during traversal.
This addresses the data race, but has further costs for concurrency, since locking the entire list while iterating could block other threads from accessing the list for a long time.