One: JDk1.7 and previous HashMap

Transfer () method in resize () method will be called when HashMap is expanded. In this case, due to the head insertion method, a circular linked list may appear in the case of multi-threading, so data loss will be caused when the following data is located to this linked list. And reading can lead to an endless loop.

2: jdk1.8 HashMap

The HashMap of 1.8 has been optimized for this. Resize uses tail insertion, i.e. the order of the original list is not changed, so there is no problem with the circular list of 1.7. But it’s not thread-safe either. Unsafe as follows:

In the case of multithreading, the inserted array subscripts calculated by PUT may be the same, and the values may be overwritten, resulting in inaccurate size.