Code Runtime Environment:
1. Download zookeeper-3.4.*.tar.gz Source Package
2. Create a new Java Project, such as TestProject
3, see inside the Zookeeper-3.4.*/recipes/lock directory, according to the source package path paste to TestProject.
1) writelocktest associated classes more will not copy
2) Curator's jar package download https://repo1.maven.org/maven2/org/apache/curator/curator-recipes/
Curator Home: http://curator.apache.org/curator-examples/index.html
The other jars are in the Zookeeper unpacking package.
4, download the example of zookeeper lock
Https://github.com/sleberknight/zookeeper-samples/tree/master/src/main/java/com/nearinfinity/examples/zookeeper
This package provides 4 ways to run, such as a red callout, and if you only run Workerusingblockingwritelock, you do not need a curator jar
If you run Workerusingcurator and workerusingwritelockrecipe, you need to curator the jar.
Below we run Workerusingblockingwritelock, because the purpose is to understand the principle, only to run a client on this machine, the output is as follows: