public abstract class

Lock

extends Object
java.lang.Object
   ↳ org.apache.lucene.store.Lock

Class Overview

An interprocess mutex lock.

Typical use might look like:

 new Lock.With(directory.makeLock("my.lock")) {
     public Object doBody() {
       ... code to execute while locked ...
     }
   }.run();
 

See Also

Summary

Nested Classes
class Lock.With Utility class for executing code with exclusive access. 
Constants
long LOCK_OBTAIN_WAIT_FOREVER Pass this value to obtain(long) to try forever to obtain the lock.
Fields
public static long LOCK_POLL_INTERVAL How long obtain(long) waits, in milliseconds, in between attempts to acquire the lock.
protected Throwable failureReason If a lock obtain called, this failureReason may be set with the "root cause" Exception as to why the lock was not obtained.
Public Constructors
Lock()
Public Methods
abstract boolean isLocked()
Returns true if the resource is currently locked.
abstract boolean obtain()
Attempts to obtain exclusive access and immediately return upon success or failure.
boolean obtain(long lockWaitTimeout)
Attempts to obtain an exclusive lock within amount of time given.
abstract void release()
Releases exclusive access.
[Expand]
Inherited Methods
From class java.lang.Object

Constants

public static final long LOCK_OBTAIN_WAIT_FOREVER

Pass this value to obtain(long) to try forever to obtain the lock.

Constant Value: -1 (0xffffffffffffffff)

Fields

public static long LOCK_POLL_INTERVAL

How long obtain(long) waits, in milliseconds, in between attempts to acquire the lock.

protected Throwable failureReason

If a lock obtain called, this failureReason may be set with the "root cause" Exception as to why the lock was not obtained.

Public Constructors

public Lock ()

Public Methods

public abstract boolean isLocked ()

Returns true if the resource is currently locked. Note that one must still call obtain() before using the resource.

Throws
IOException

public abstract boolean obtain ()

Attempts to obtain exclusive access and immediately return upon success or failure.

Returns
  • true iff exclusive access is obtained
Throws
IOException

public boolean obtain (long lockWaitTimeout)

Attempts to obtain an exclusive lock within amount of time given. Polls once per LOCK_POLL_INTERVAL (currently 1000) milliseconds until lockWaitTimeout is passed.

Parameters
lockWaitTimeout length of time to wait in milliseconds or LOCK_OBTAIN_WAIT_FOREVER to retry forever
Returns
  • true if lock was obtained
Throws
LockObtainFailedException if lock wait times out
IllegalArgumentException if lockWaitTimeout is out of bounds
IOException if obtain() throws IOException

public abstract void release ()

Releases exclusive access.

Throws
IOException