Zookeeper distributed lock steps: 1. Zookeeper is a node with nodes, similar to a file directory, so we abstract the lock into a directory, zookeeper has a node of EPHEMERAL_SEQUENTIAL types, multiple threads and when the node created by zookeeper, it will help us arrange the order to create, so the directories under this node are sequential. 2. Get the smallest node of the current directory, determine whether the smallest node is the current node, if it means that the lock is successful, if it is not the lock acquisition failure. 3. When the lock fails, in order to avoid the swarm effect, what you have to do is to obtain the previous node of the current node, and then listen to the node. 4. When you do this, when you release the lock, you will also notify the next node. |