What does it mean when we say an ArrayList is not synchronized?

前端 未结 6 1535

What does it mean when we say an ArrayList is not synchronized?

Does it mean that if we declare an ArrayList in object scope, multiple threads accessing the objects hav

6条回答
  •  孤独总比滥情好
    2021-02-07 05:44

    Being synchronized means that every operation is thread safe - if you use the same Array List from two threads at the same time, they can't corrupt the state. However, this makes it slower.

    By default ArrayList is not synchronized, you can achieved that by synchronized keyword

    ArrayList al=new ArrayList();
    
    Collections.synchronized(al);
    

提交回复
热议问题