8.8. 闭锁(CountDownLatch)

基于Redisson的Redisson分布式闭锁(CountDownLatch)Java对象RCountDownLatch采用了与java.util.concurrent.CountDownLatch相似的接口和用法。

  1. RCountDownLatch latch = redisson.getCountDownLatch("anyCountDownLatch");
  2. latch.trySetCount(1);
  3. latch.await();
  4. // 在其他线程或其他JVM里
  5. RCountDownLatch latch = redisson.getCountDownLatch("anyCountDownLatch");
  6. latch.countDown();