RLock rLock = redissonClient.getLock("CALCULATE_PROFIT");
try {
boolean acquireLock = rLock.tryLock(1, 120, TimeUnit.SECONDS);
if (acquireLock){
//业务逻辑代码
}else{
return BaseResponse.Error("500", "请稍后重试!");
}
} catch (Exception e) {
e.printStackTrace();
}finally {
if (rLock.isHeldByCurrentThread()){
rLock.unlock();
}
}
原文:https://www.cnblogs.com/RenChenHao/p/15355965.html