All Packages This Package Previous Next
java.lang.Object | +----java.util.Lock
The programmer using locks must be responsible for clearly defining the semantics of their use and should handle deadlock avoidance in the face of exceptions.
For example, if you want to protect a set of method invocations with a lock, and one of the methods may throw an exception, you must be prepared to release the lock similarly to the following example:
class SomeClass {
Lock myLock = new Lock();
void someMethod() {
myLock.lock();
try {
StartOperation();
ContinueOperation();
EndOperation();
} finally {
myLock.unlock();
}
}
}
public Lock()
public final synchronized void lock()
public final synchronized void unlock()
All Packages This Package Previous Next