public abstract class Lock extends Object
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.With
Utility class for executing code with exclusive access.
|
| Modifier and Type | Field and Description |
|---|---|
static long |
LOCK_POLL_INTERVAL |
| Constructor and Description |
|---|
Lock() |
| Modifier and Type | Method and Description |
|---|---|
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.
|
public static final long LOCK_POLL_INTERVAL
public abstract boolean obtain()
throws IOException
IOExceptionpublic boolean obtain(long lockWaitTimeout)
throws IOException
lockWaitTimeout - length of time to wait in msIOException - if lock wait times out or obtain() throws an IOExceptionpublic abstract void release()
public abstract boolean isLocked()
obtain() before using the resource.Copyright © 2024 GATE. All rights reserved.