| threaddemo.locking.RWLock
All known Subclasses: threaddemo.locking.MonitorLock, threaddemo.locking.EventLock, threaddemo.locking.EventHybridLock,
RWLock | public interface RWLock (Code) | | Some kind of a lock, with support for possible read and write modes.
Examples of use:
Lock m = Locks.readWriteLock("foo", 0);
// Grant write access, compute an integer and return it:
return m.write(new LockAction() {
public Integer run() {
return 1;
}
});
// Obtain read access, do some computation, possibly throw an IOException:
m.read(new LockExceptionAction() {
public Void run() throws IOException {
if (...) throw new IOException();
return null;
}
});
See Also: Locks author: Jesse Glick |
Method Summary | |
boolean | canRead() Check if the current thread is holding a read or write lock. | boolean | canWrite() Check if the current thread is holding the write lock. | T | read(LockAction<T> action) Run an action only with read access. | T | read(LockExceptionAction<T, E> action) Run an action with read access and possibly throw a checked exception. | void | read(Runnable action) Run an action with read access, returning no result. | void | readLater(Runnable action) Run an action asynch with read access. | T | write(LockAction<T> action) Run an action with write access. | T | write(LockExceptionAction<T, E> action) Run an action with write access and possibly throw an exception. | void | write(Runnable action) Run an action with write access and return no result. | void | writeLater(Runnable action) Run an action asynchronously with write access. |
canRead | boolean canRead()(Code) | | Check if the current thread is holding a read or write lock.
true if either read or write access is available |
canWrite | boolean canWrite()(Code) | | Check if the current thread is holding the write lock.
Note that this will be false in case write access was entered and then
read access was entered inside of that, until the nested read access is
again exited.
true if write access is available |
read | T read(LockAction<T> action)(Code) | | Run an action only with read access.
Parameters: action - the action to perform the object returned from LockAction.run |
read | T read(LockExceptionAction<T, E> action) throws E(Code) | | Run an action with read access and possibly throw a checked exception.
Note that runtime exceptions are always passed through, and neither
require this invocation style, nor are encapsulated.
Parameters: action - the action to execute the object returned from LockExceptionAction.run throws: E - a checked exception, if any throws: RuntimeException - if any runtime exception is thrown from the run method See Also: RWLock.read(LockAction) |
write | T write(LockAction<T> action)(Code) | | Run an action with write access.
May not be called while holding read access.
Parameters: action - the action to perform the result of LockAction.run |
|
|