Concurrent threads adding to ArrayList at same time - what happens?

后端 未结 9 1901
星月不相逢
星月不相逢 2020-11-28 05:28

We have multiple threads calling add(obj) on an ArrayList.

My theory is that when add is called concurrently by two threads,

9条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-28 06:26

    you can use List l = Collections.synchronizedList(new ArrayList()); if you want thread safe version of arrayList.

提交回复
热议问题