Collections.synchronizedList and synchronized

前端 未结 6 1961
星月不相逢
星月不相逢 2020-11-27 11:36
List list = Collections.synchronizedList(new ArrayList());
synchronized (list) {
    list.add(\"message\");
}

Is the bl

6条回答
  •  难免孤独
    2020-11-27 12:06

    The underlying code for Collections.synchronizedList add method is:

    public void add(int index, E element) {
        synchronized (mutex) {list.add(index, element);}
    }
    

    So in your example it is not needed to add synchronisation.

提交回复
热议问题