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.
因为垃圾收集器线程和写入者线程可能同时尝试修改全局列表,所以同样也需要使用某种锁定机制。
It implements List and is thread-safe, but its iterators will not throw ConcurrentModificationException and do not require any additional locking during traversal.
它实现了List,而且是线程安全的,但是它的迭代器不会抛出ConcurrentModificationException,遍历期间也不要求额外的锁定。
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.
这样做虽然解决了数据争用问题,但是在并发性方面付出了更多的代价,因为在迭代期间锁住整个list会阻塞其他线程,使它们在很长一段时间内不能访问这个列表。
应用推荐