It seems that this behavior is due to a change in the internal implementation of the HashMap PUT method in the latest version of Java 7. After passing through the source code of several versions, I found the answer to my question
The hashMap put method calls addEntry () to add a new record -
public V put(K key, V value) { ... int hash = hash(key); int i = indexFor(hash, table.length); ... addEntry(hash, key, value, i); ... }
jdk7-b147 The HashMap.addEntry method looks like
addEntry(int hash, K key, V value, int bucketIndex) { Entry<K,V> e = table[bucketIndex]; table[bucketIndex] = new Entry<>(hash, key, value, e); if (size++ >= threshold) resize(2 * table.length); }
The source code of version 1.7.0_67-b01 looks like
void addEntry(int hash, K key, V value, int bucketIndex) { if ((size >= threshold) && (null != table[bucketIndex])) { resize(2 * table.length); hash = (null != key) ? hash(key) : 0; bucketIndex = indexFor(hash, table.length); } createEntry(hash, key, value, bucketIndex); }
Thus, in recent versions of Java, the HashMap cannot be changed depending on the threshold. If the bucket is empty, recording will continue without resizing the HashMap
Java 8 may have different behavior, source code version 8-b132 shows that PUT is completely repeated -
put(K key, V value) { return putVal(hash(key), key, value, false, true); } putVal(int hash, K key, V value, boolean onlyIfAbsent,boolean evict) { Node<K,V>[] tab; Node<K,V> p; int n, i; if ((tab = table) == null || (n = tab.length) == 0) n = (tab = resize()).length; .... } final Node<K,V>[] resize() {
A Java document cannot be updated as often as Java versions! Thanks Steven