Interface DistributedLock

All Known Implementing Classes:
CaffeineDistributedLock, RedisDistributedLock

public interface DistributedLock
分布式锁顶级接口 例如: RETRY_TIMES=100,SLEEP_MILLIS=100 RETRY_TIMES * SLEEP_MILLIS = 10000 意味着如果一直获取不了锁,最长会等待10秒后抛超时异常
Author:
zuihou
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    重试次数
    static final long
    每次重试后等待的时间 单位:毫秒
    static final long
    默认超时时间 单位:毫秒
  • Method Summary

    Modifier and Type
    Method
    Description
    default boolean
    lock(String key)
    获取锁
    default boolean
    lock(String key, int retryTimes)
    获取锁
    default boolean
    lock(String key, int retryTimes, long sleepMillis)
    获取锁
    default boolean
    lock(String key, long expire)
    获取锁
    default boolean
    lock(String key, long expire, int retryTimes)
    获取锁
    boolean
    lock(String key, long expire, int retryTimes, long sleepMillis)
    获取锁
    boolean
    释放锁
  • Field Details

    • TIMEOUT_MILLIS

      static final long TIMEOUT_MILLIS
      默认超时时间 单位:毫秒
      See Also:
    • RETRY_TIMES

      static final int RETRY_TIMES
      重试次数
      See Also:
    • SLEEP_MILLIS

      static final long SLEEP_MILLIS
      每次重试后等待的时间 单位:毫秒
      See Also:
  • Method Details

    • lock

      default boolean lock(String key)
      获取锁
      Parameters:
      key - key
      Returns:
      成功/失败
    • lock

      default boolean lock(String key, int retryTimes)
      获取锁
      Parameters:
      key - key
      retryTimes - 重试次数
      Returns:
      成功/失败
    • lock

      default boolean lock(String key, int retryTimes, long sleepMillis)
      获取锁
      Parameters:
      key - key
      retryTimes - 重试次数
      sleepMillis - 获取锁失败的重试间隔 单位:毫秒
      Returns:
      成功/失败
    • lock

      default boolean lock(String key, long expire)
      获取锁
      Parameters:
      key - key
      expire - 获取锁超时时间
      Returns:
      成功/失败
    • lock

      default boolean lock(String key, long expire, int retryTimes)
      获取锁
      Parameters:
      key - key
      expire - 获取锁超时时间
      retryTimes - 重试次数
      Returns:
      成功/失败
    • lock

      boolean lock(String key, long expire, int retryTimes, long sleepMillis)
      获取锁
      Parameters:
      key - key
      expire - 获取锁超时时间
      retryTimes - 重试次数
      sleepMillis - 获取锁失败的重试间隔
      Returns:
      成功/失败
    • releaseLock

      boolean releaseLock(String key)
      释放锁
      Parameters:
      key - key值
      Returns:
      释放结果