Redisson lockup

1. Overview of Locking

The Redisson distributed latch (CountDownLatch) Java object RCountDownLatch uses a similar interface and usage to java.util.concurrent.CountDownLatch.

2. Practice

RCountDownLatch latch = redisson.getCountDownLatch("anyCountDownLatch");
latch.trySetCount(3); // redis中存在一个anyCountDownLatch=3,当其等于0时就闭锁
latch.await();
// 在其他线程或其他JVM里
RCountDownLatch latch = redisson.getCountDownLatch("anyCountDownLatch");
latch.countDown(); // redis中的anyCountDownLatch减一

Guess you like

Origin blog.csdn.net/sinat_34241861/article/details/112364979