说明
使用参考 Jdk中的CountDownLatch,
配置文件参考:https://blog.csdn.net/qq_38428623/article/details/123217001?utm_source=app&app_version=5.1.1&code=app_1562916241&uLinkId=usr1mkqgl919blen
使用参考
package com.demo.redis.string;
import org.redisson.api.RCountDownLatch;
import org.redisson.api.RedissonClient;
import org.springframework.util.Assert;
import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;
/**
* RedisCountDownLatch
*
* @author 王思勤
*/
public class RedisCountDownLatch {
@Resource
private RedissonClient redissonClient;
/**
* 获取 字符串 的 RAtomicLong
*
* @param name 名称
* @return 返回 值
*/
public RCountDownLatch getCountDownLatch(String name) {
RCountDownLatch countDownLatch = redissonClient.getCountDownLatch(name);
Assert.notNull(countDownLatch, "countDownLatch is null");
return countDownLatch;
}
/**
* 设置 数量
*
* @param name 名称
* @param count 数量
* @return 返回 是否设置成功
*/
public boolean trySetCount(String name, long count) {
return this.getCountDownLatch(name).trySetCount(count);
}
/**
* countDown
*
* @param name 名称
*/
public void countDown(String name) {
this.getCountDownLatch(name).countDown();
}
/**
* await
*
* @param name 名称
* @throws InterruptedException interruptedException
*/
public void await(String name) throws InterruptedException {
this.getCountDownLatch(name).await();
}
/**
* await
*
* @param name 名称
* @param timeout 超时时间
* @param timeUnit 超时时间的单位
* @throws InterruptedException interruptedException
*/
public void await(String name, long timeout, TimeUnit timeUnit) throws InterruptedException {
this.getCountDownLatch(name).await(timeout, timeUnit);
}
}