Class Lock

All Implemented Interfaces:
Closeable, AutoCloseable

public abstract class Lock extends Object implements Closeable
An interprocess mutex lock.

Typical use might look like:

   try (final Lock lock = directory.obtainLock("my.lock")) {
     // ... code to execute while locked ...
See Also:
NOTE: This API is for internal purposes only and might change in incompatible ways in the next release.
  • Constructor Details

    • Lock

      public Lock()
  • Method Details

    • close

      public abstract void close() throws IOException
      Releases exclusive access.

      Note that exceptions thrown from close may require human intervention, as it may mean the lock was no longer valid, or that fs permissions prevent removal of the lock file, or other reasons.

      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      LockReleaseFailedException - optional specific exception) if the lock could not be properly released.
    • ensureValid

      public abstract void ensureValid() throws IOException
      Best effort check that this lock is still valid. Locks could become invalidated externally for a number of reasons, for example if a user deletes the lock file manually or when a network filesystem is in use.
      IOException - if the lock is no longer valid.