当我们说一个ArrayList不同步是什么意思? [英] What does it mean when we say an ArrayList is not synchronized?

查看:99
本文介绍了当我们说一个ArrayList不同步是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我们说一个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不同步是什么意思?

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

这意味着从多个线程访问 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,访问对象的多个线程就有机会修改列表?

Does it mean that if we declare an ArrayList in object scope, multiple threads accessing the objects have the opportunity to modify the list?

即使它是线程安全的,多个线程也可以修改列表.

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不同步是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆