重要的几个方法
lock:加锁
tryLock:尝试获取锁
unlock:解锁
isLock:是否被锁
isHeldByCurrentThread:是否被当前线程锁
isHeldByThread:是否被指定线程锁
getName:获取锁的名字
其中最重要的是前面三者
解锁时判断锁是否在当前线程以便满足独占性
RLock
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//
package org.redisson.api;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Lock;
public interface RLock extends Lock, RLockAsync {
// 获取锁名字
String getName();
// 中断锁操作 Thread.currentThread().interrupt(); 方法真正中断该线程
void lockInterruptibly(long var1, TimeUnit var3) throws InterruptedException;
/**
* 尝试获取锁
* waitTimeout 尝试获取锁的最大等待时间,超过这个值,则认为获取锁失败
* leaseTime 锁的持有时间,超过这个时间锁会自动失效
*(值应设置为大于业务处理的时间,确保在锁有效期内业务能处理完)
**/
boolean tryLock(long waitTime, long leaseTime, TimeUnit unit) throws InterruptedException;
// 加锁 锁的有效期设置为 leaseTime,过期后自动失效,如果 leaseTime 设置为 -1, 表示不主动过期
void lock(long leaseTime, TimeUnit unit);
// Unlocks the lock independently of its state
boolean forceUnlock();
// 检查是否被锁住
boolean isLocked();
// 检查当前线线程是否持有该锁
boolean isHeldByThread(long var1);
// 检查指定线程是否持有锁
boolean isHeldByCurrentThread();
// 返回当前线程持有锁的次数
int getHoldCount();
/**
* 返回锁的剩余时间
* @return time in milliseconds
* -2 if the lock does not exist.
* -1 if the lock exists but has no associated expire.
*/
long remainTimeToLive();
}