org.apache.lucene.store
abstract public static class: Lock.With [javadoc |
source]
java.lang.Object
org.apache.lucene.store.Lock$With
Utility class for executing code with exclusive access.
Constructor: |
public With(Lock lock,
long lockWaitTimeout) {
this.lock = lock;
this.lockWaitTimeout = lockWaitTimeout;
}
Constructs an executor that will grab the named lock. |
Method from org.apache.lucene.store.Lock$With Summary: |
---|
doBody, run |
Methods from java.lang.Object: |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method from org.apache.lucene.store.Lock$With Detail: |
abstract protected Object doBody() throws IOException
Code to execute with exclusive access. |
public Object run() throws LockObtainFailedException, IOException {
boolean locked = false;
try {
locked = lock.obtain(lockWaitTimeout);
return doBody();
} finally {
if (locked)
lock.release();
}
}
Calls #doBody while lock is obtained. Blocks if lock
cannot be obtained immediately. Retries to obtain lock once per second
until it is obtained, or until it has tried ten times. Lock is released when
#doBody exits. |