分布式锁三种解决方案

分布式系统中,为了解决执行代码片段/或者任务的唯一性,提出了分布式锁的概念

目前常用的有三种实现方式

1:基于redis的实现

2:基于zk的实现

3:基于db的实现

final DbDistributedLockTemplate template = new DbDistributedLockTemplate();
    
    public void init(){
        template.execute("shchgateway", 2000, new Callback() {
            
            @Override
            public Object onTimeout() throws InterruptedException {
                // TODO Auto-generated method stub
                return null;
            }
            
            @Override
            public Object onGetLock() throws InterruptedException {
                // TODO Auto-generated method stub
                return null;
            }
        });
    }

猜你喜欢

转载自www.cnblogs.com/lhl-shubiao/p/10729465.html