@Test
public void testDistributeLock() throws InterruptedException {
final CountDownLatch cdl = new CountDownLatch(10);
long time = System.currentTimeMillis();
RedissonClient redisson = Redisson.create();
final RLock rLock = redisson.getLock("hello-lock");
final Map<String, Integer> map = new HashMap<>(1);
map.put("hello", 0);
for (int i = 0; i < 10; i++) {
new Thread(new Runnable() {
@Override
public void run() {
rLock.lock(10, TimeUnit.SECONDS);
map.put("hello", map.get("hello") + 1);
rLock.unlock();
cdl.countDown();
}
}).start();
}
cdl.await();
System.out.println("result ->" + map.get("hello"));
System.out.println(System.currentTimeMillis() - time);
}
redisson lock