Interface Lock

All Superinterfaces:
AutoCloseable
All Known Implementing Classes:
NoOpLock

public interface Lock extends AutoCloseable
Interface of a lock acquired to gain (exclusive) access to a shared resource, with a mechanism to release it again.

This lock is a AutoCloseable resource, so will be released automatically if declared in a try-with-resources block.

Since:
3.0
Author:
Rene de Waele
  • Method Summary

    Modifier and Type
    Method
    Description
    default void
    Releases this lock.
    boolean
    Indicates whether the lock is still owned true, or whether it has been released false.
    void
    Releases this lock.
  • Method Details

    • close

      default void close()
      Releases this lock. By default this simply calls release().

      Specified by:
      close in interface AutoCloseable
    • release

      void release()
      Releases this lock. If this lock is already released or no longer valid, the behavior of this method is undefined.
    • isHeld

      boolean isHeld()
      Indicates whether the lock is still owned true, or whether it has been released false.
      Returns:
      true if the lock is still valid, or false if it has been released