|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Object | +--gov.sns.tools.Lock
Lock allows an alternative method to Java's synchronize feature
for locking resources from other threads. The reason for this alternative is
to provide the ability to test for a lock without waiting. Lock has methods
for both waiting for a lock and testing for a lock. If a lock is held by
the same thread requesting it, the lock is immediately granted. Every lock
must be balanced by a call to unlock(). The lock is freed only
when all locks have been relinquished.
| Constructor Summary | |
Lock()
Creates a new instance of Lock |
|
| Method Summary | |
boolean |
lock()
Request a lock and wait until the lock is granted. |
boolean |
tryLock()
Try to get a lock. |
void |
unlock()
Relinquish the lock. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
public Lock()
| Method Detail |
public boolean lock()
unlock() to
relinquish the lock.
unlock()public void unlock()
public boolean tryLock()
if( lock.tryLock() ) {
// some code here...
lock.unlock();
}
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||