Java Synchronized list

后端 未结 7 2091
一整个雨季
一整个雨季 2020-12-01 06:13

I have a pre-populated array list. And I have multiple threads which will remove elements from the array list. Each thread calls the remove method below and removes one item

相关标签:
7条回答
  • 2020-12-01 06:46

    From Collections#synchronizedList(List) javadoc

    Returns a synchronized (thread-safe) list backed by the specified list. In order to guarantee serial access, it is critical that all access to the backing list is accomplished through the returned list ... It is imperative that the user manually synchronize on the returned list when iterating over it. Failure to follow this advice may result in non-deterministic behavior.

    0 讨论(0)
提交回复
热议问题