Author | according to Ben affectionate

Original text: blog.csdn.net/qq_36520235/article/details/86653136

The first state:

When thread 1 has just expanded the array, it is about to rehash, but thread 2 is forced to insert it and thread 2 has rehash completed.




The second state:

This thread has been awakened, begin to rehash operation, the key is 5 nodes or hung on the location of the array subscript 1, and is the key to the back of the 5 9 this node (here actually before for expansion and an array of four, then certainly need to reposition the subscript, so here is to take more than 4, And then look up the corresponding array subscript in the linked list)

The third state:

Proceed from the first state to the node with key 9, so it should be on the bucket list with index 1 in the order of 9—->5—->NULL



The fourth state:

At this point, after processing 9 in step 3, he finds that node 9 is followed by node 5 (the node 5 is left because thread 2 has rehashed), At this point, he will put node 5 at the head of thread 1, which is 5—->9—-5(the latter part of the 9- >5 is reserved for the third state), forming an infinite loop.



The last

Welcome to pay attention to the public number: programmer chasing wind, reply 66, get a 300 page PDF document Java core knowledge summary!

These are some of the things that the interviewer should ask during the interview. These include basics, Java collections, JVMS, multi-threaded concurrency, Spring principles, microservices, Netty and RPC, Kafka, diaries, design patterns, Java algorithms, databases, Zookeeper, distributed caching, data structures, and more.