java 多线程hashset_java – HashSet和多线程

我在Java 7上工作.

我想知道方法包含的HashSet对象是否是线程安全的.

HashSet由一个线程初始化.然后我们用不可修改的集合(Collections.unmodifiableSet)包装HashSet.初始化后,多个线程只调用方法contains.

当我读到Javadoc时,对我来说还不清楚.

This class implements the Set interface, backed by a hash table (actually a HashMap instance).

Note that this implementation is not synchronized.

Note that this implementation is not synchronized. If multiple threads access a hash map concurrently, and at least one of the threads modifies the map structurally, it must be synchronized externally. (A structural modification is any operation that adds or deletes one or more mappings; merely changing the value associated with a key that an instance already contains is not a structural modification.)

对我来说,这意味着方法包含的不是结构修改.

所以多次调用方法包含它是否是线程安全的?

如果是真的:JVM的所有实现(如IBM JVM)都能保证吗?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值