哪些所有Java集合都是同步的,而不是同步的 [英] Which all Java Collections are synchronized and not synchronized
本文介绍了哪些所有Java集合都是同步的,而不是同步的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
哪些所有Java集合已同步且未同步
Which all Java Collections are synchronized and not synchronized
示例:HashSet未同步
Example: HashSet is not synchronized
推荐答案
有三组集合。
- Java 1.0集合,这包括Hashtable,Vector,Stack。这些是同步的,但我不建议你使用它们。属性可能是一个例外,但我不会在多线程上下文中使用它。
- 在1998年添加的Java 1.2集合在很大程度上取代了这些集合,但不能同步,使用
Collections.synchronizedXxx()
方法 - 2004年增加的Java 5.0并发集合支持锁定自由,线程安全集合。
- Java 1.0 collections which mostly legacy classes. This includes Hashtable, Vector, Stack. These are synchronized but I don't recommend you use them. Properties is perhaps one exception, but I wouldn't use it in a multi-threaded context.
- Java 1.2 collections added in 1998 which largely replaced these collection are not synchronized, but can be synchronized using
Collections.synchronizedXxx()
methods - Java 5.0 concurrency collections added in 2004 support lock free, thread safe collections.
简而言之,我建议您不要使用的任何集合都会同步。
In short, none of the collections I would recommend you use are synchronized.
这篇关于哪些所有Java集合都是同步的,而不是同步的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文