Save This Page
Home » openjdk-7 » sun » misc » [javadoc | source]
public class: Lock [javadoc | source]

Direct Known Subclasses:

The Lock class provides a simple, useful interface to a lock. Unlike monitors which synchronize access to an object, locks synchronize access to an arbitrary set of resources (objects, methods, variables, etc.).

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() {
             try {
             } finally {
 public Lock() 
Method from sun.misc.Lock Summary:
lock,   unlock
Methods from java.lang.Object:
clone,   equals,   finalize,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from sun.misc.Lock Detail:
 public final synchronized  void lock() throws InterruptedException 
    Acquire the lock. If someone else has the lock, wait until it has been freed, and then try to acquire it again. This method will not return until the lock has been acquired.
 public final synchronized  void unlock() 
    Release the lock. If someone else is waiting for the lock, the will be notitified so they can try to acquire the lock again.