Coder Social home page Coder Social logo

d-lock's Introduction

d-lock

d为db指的是数据库,或者"Distributed lock"中的d。

在实际业务开发中,并不一定所有的场景都需要高性能的分布式锁,比如基于redis,zookeeper。有点时候,也需要基于数据库的分布式锁。 对性能要求不高,但是因为项目本身就已经用到了mysql,没有必要再引用一个多余的中间件产品。

设计过程的一些思考

要不要绑定spring事务上下文

因为锁本身是必须在finally中unlock的,所以不需要和spring事务关联,并且就算业务失败,分布式锁也不应该回退到之前的数据。 绑定spring事务参考"DataSourceUtils.getConnection(dataSource);" 和 "spring jdbctemplate"

要不要select for update

会占用mysql的链接,所以不使用, 比较适合等待排他锁,但是不适合不等待的排他锁

加锁insert,解锁delete

这种方法没有考虑到锁超时,如果出现锁超时,又需要检查数据。

d-lock's People

Contributors

xhrg avatar

Watchers

 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.