缓存-分布式锁-Redisson-闭锁测试

/**
 * 放假、锁门
 * 1班没人了
 * 5个班,全部走完,我们才可以锁大门
 * 分布式闭锁
 */

@GetMapping(value = "/lockDoor")
@ResponseBody
public String lockDoor() throws InterruptedException {

    RCountDownLatch door = redisson.getCountDownLatch("door");
    door.trySetCount(5);
    door.await();       //等待闭锁完成

    return "放假了...";
}

@GetMapping(value = "/gogogo/{id}")
@ResponseBody
public String gogogo(@PathVariable("id") Long id) {
    RCountDownLatch door = redisson.getCountDownLatch("door");
    door.countDown();       //计数-1

    return id + "班的人都走了...";
}

 

你可能感兴趣的:(缓存-分布式锁-Redisson-闭锁测试)