Module utilities

Interface Lock


public interface Lock
A Lock on a Lockable resource is either a read lock or an exclusive write lock. It is acquired indirectly by one of the execute methods in Lockable.
Author:
Ole Kniemeyer
  • Method Details

    • getLockable

      Lockable getLockable()
      Returns the resource on which this lock is held.
      Returns:
      resource locked by this lock
    • retain

      void retain()
      A lock may be retained by invocation of this method within the LockProtectedRunnable.run(boolean, Lock) method of a task. In this case, the lock is not released after the task has been finished: The lock remains active and has to be passed to one of the execute methods in Lockable which take a lock as parameter, only then the lock will be released.
    • executeWithoutWriteLock

      void executeWithoutWriteLock(Runnable callback) throws InterruptedException
      Executes callback while temporarily reducing this write lock to a read lock. This gives threads waiting for a read lock the chance to execute.
      Throws:
      IllegalStateException - if this lock is not a write lock
      InterruptedException - if this thread is interrupted while reacquiring the write lock. In this case the lock stays a read lock
    • isWriteLock

      boolean isWriteLock()
      Returns the type of lock.
      Returns:
      is this lock a read or write lock?