Coder Social home page Coder Social logo

distributedlock-spring-boot-starter's Introduction

distributedlock-spring-boot-starter

简化分布式锁的使用,提供基于spring-boot自动配置的starter

QuickStart

下载编译

git clone [email protected]:pcbest/distributedlock-spring-boot-starter.git
cd distributedlock-spring-boot-starter; 
mvn clean install -Dmaven.test.skip -Denv=release

使用

添加依赖

<dependency>
    <groupId>com.liuzm.paascloud</groupId>
    <artifactId>distributedlock-spring-boot-starter</artifactId>
    <version>${bulid.version}</version>
</dependency>

配置

application.properties或者application.yml
# 必须配置
distributedlock.zk.zkAddressList=127.0.0.1:2181
或者
distributedlock.zk.zkAddressList=ip1:2181,ip1,ip1:2181

# 可不配置
distributedlock.zk.namespace=lock

获取锁释放锁

    final String lockPath = "/testlok";
    boolean res = false;
    try {
        res = zkLock.lock(lockPath, 3, TimeUnit.SECONDS);
        if (res) {
            // 获取到了锁 do something
        } else {
            System.out.println(Thread.currentThread().getName() + "未获取到锁");
            // 未获取到锁 do something
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        //释放锁
        if (res) {
            zkLock.unlock(lockPath);
        }
    }

distributedlock-spring-boot-starter's People

Contributors

gsfeng179 avatar

Stargazers

 avatar  avatar  avatar 无痕 avatar

Watchers

James Cloos avatar  avatar 无痕 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.