Exclusive Lock Concept:
Exclusive Locks, known as X-Lock, write-lock, exclusive-lock. If a thing T1 a data object O1 with exclusive locks, only the transaction T1 read and write to the O1 during the entire lock-up, and other transactions must wait until the T1 releases the lock before the operation can be performed. In a stand-alone environment, The JDK provides the Synchronized keyword and reentrantlock
The ability to reuse locks to provide exclusive locks.
Zookeeper implementation of the exclusive lock principle:
When you need to obtain an exclusive lock, all clients call the Create method under the fixed path of creating the node, in the concurrent environment, only one client can create a success, the equivalent of acquiring a lock, when the client completes the transaction, the node is deleted. For other nodes that did not succeed, set the listener on that path. If the path child node deletes an event trigger, continue to try to acquire the lock (create).
Specific implementation:
Define the interface of the Lock: (Several methods I want to implement)
Public Interface Distributedlock { void lock (); Boolean isLocked (); Boolean Trylock (); boolean trylock (long timeout); void unlock ();}
Distributed lock----Zookeeper practice (exclusive lock)