Zookeeper Application Scenario-example of a distributed lock implementation

Source: Internet
Author: User
Tags zookeeper

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:



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.