public abstract class Lock extends Object implements Closeable
Typical use might look like:
 new Lock.With(directory.makeLock("my.lock")) {
     public Object doBody() {
       ... code to execute while locked ...
     }
   }.run();
 Directory.makeLock(String)| Modifier and Type | Class and Description | 
|---|---|
| static class  | Lock.WithUtility class for executing code with exclusive access. | 
| Modifier and Type | Field and Description | 
|---|---|
| protected Throwable | failureReasonIf a lock obtain called, this failureReason may be set
 with the "root cause" Exception as to why the lock was
 not obtained. | 
| static long | LOCK_OBTAIN_WAIT_FOREVERPass this value to  obtain(long)to try
  forever to obtain the lock. | 
| static long | LOCK_POLL_INTERVALHow long  obtain(long)waits, in milliseconds,
  in between attempts to acquire the lock. | 
| Constructor and Description | 
|---|
| Lock() | 
| Modifier and Type | Method and Description | 
|---|---|
| abstract void | close()Releases exclusive access. | 
| 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. | 
public static long LOCK_POLL_INTERVAL
obtain(long) waits, in milliseconds,
  in between attempts to acquire the lock.public static final long LOCK_OBTAIN_WAIT_FOREVER
obtain(long) to try
  forever to obtain the lock.protected Throwable failureReason
public abstract boolean obtain()
                        throws IOException
close() to
  release the lock.IOExceptionpublic final boolean obtain(long lockWaitTimeout)
                     throws IOException
LOCK_POLL_INTERVAL
  (currently 1000) milliseconds until lockWaitTimeout is
  passed.lockWaitTimeout - length of time to wait in
        milliseconds or LOCK_OBTAIN_WAIT_FOREVER to retry foreverLockObtainFailedException - if lock wait times outIllegalArgumentException - if lockWaitTimeout is
         out of boundsIOException - if obtain() throws IOExceptionpublic abstract void close()
                    throws IOException
close in interface Closeableclose in interface AutoCloseableIOExceptionpublic abstract boolean isLocked()
                          throws IOException
obtain() before using the resource.IOExceptionCopyright © 2000-2015 Apache Software Foundation. All Rights Reserved.