问题描述
当我们说 ArrayList 不同步是什么意思?
What does it mean when we say an ArrayList is not synchronized?
是不是说如果我们在对象范围内声明一个ArrayList,访问对象的多个线程都有机会修改列表?
Does it mean that if we declare an ArrayList in object scope, multiple threads accessing the objects have the opportunity to modify the list?
推荐答案
这意味着从多个线程访问 ArrayList
实例可能不安全(阅读,可能导致意外行为"或可能无法像宣传的那样工作").
It means that accessing an ArrayList
instance from multiple threads may not be safe (read, "may result in unexpected behavior" or "may not work as advertised").
进一步阅读:
是否意味着如果我们在对象范围内声明一个ArrayList,访问该对象的多个线程都有机会修改列表?
即使它是线程安全的,多个线程也可以修改列表.
Even if it would have been thread safe, multiple threads would be able to modify the list.
不同之处在于,如果它不是线程安全的并且多个线程访问该列表,则所有赌注都将关闭.说这个类不是线程安全的,就等于在每个方法描述前加上如果一次从一个线程访问,这个方法的作用如下.....".
The difference is that if it's not thread safe and multiple threads access the list, all bets are off. Saying that the class is not thread safe, is the same as adding "If accessed from one thread at a time, this method works as follows....." in front of every method description.
这篇关于当我们说 ArrayList 不同步时,这是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!