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.这句话意思是不是只改变VALUE,就可以多线程访问了?
* 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.这句话意思是不是只改变VALUE,就可以多线程访问了?
添加删除键值对是结构性的改变。
修改一个已经存在的键对应的值,不是结构上的改变。
这里没有提多线程的问题。HashMap是非线程安全的,如果想多线程安全的使用HashMap,使用java.util.concurrent.ConcurrentHashMap<K,V>
从HashMap到ConcurrentHashMap:
Map map = Collections.synchronizedMap(hashMap);
指添加或删除一个或多个映射;仅仅改变该值
带key,一个实例已经包含关联不是结构改造。
* If multiple threads access a hash map concurrently, and at least one of
* the threads modifies the map structurally, it <i>must</i> 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.) This is typically accomplished by
* synchronizing on some object that naturally encapsulates the map.两位兄弟
at least one of the threads modifies the map structurally, it must be synchronized externally.至少一个线程结构上修改了MAP,必须从外部同步。