Interface DistributedLock

All Superinterfaces:
Lock

public interface DistributedLock extends Lock
Interface to indicate a distributed lock, or one that can be shared across JVMs. Implementors of this interface must use the lock semantics of the Lock interface, but must guarantee them in a distributed environment - typically with the Lock backed by a database, cache, ZooKeeper, shared file system, etc.
Author:
Kelly Tisdell (ktisdell)
  • Field Details

    • GLOBAL_ENV_CAN_OBTAIN_LOCK_PROPERTY_NAME

      static final String GLOBAL_ENV_CAN_OBTAIN_LOCK_PROPERTY_NAME
      Default property name to determine, globally, whether this environment (JVM) can obtain a lock of this type.
  • Method Details

    • canParticipate

      boolean canParticipate()
      Indicates if the current thread, JVM, or environment can use this lock. Callers may call this method to know whether they can obtain a lock. Internally, implementations must continue to respect the normal lock semantics provided by the Lock interface. For example if this method returns false and someone calls Lock.lockInterruptibly(), then the thread must block interruptably, but should never provide a lock. Similarly, a call to {@link DistributedLock#tryLock(5000L, java.util.concurrent.TimeUnit#MILLISECONDS)}, then the thread must block for 5000 milliseconds, and then return false. This allows someone to determine if a Thread, a JVM, an environment, etc. can ever obtain a lock. Implementations are typically driven by a property, e.g. provided by Spring's Environment object.
      Returns:
      whether or not this environment can participate in acquiring this lock. If not, normal lock semantics apply, but the lock will never be acquired.
    • currentThreadHoldsLock

      boolean currentThreadHoldsLock()
      Indicates if the current thread holds the lock.
      Returns:
      returns true if the current thread holds this lock. false, otherwise.