Contents | Package | Class | Tree | Deprecated | Index | Help
PREV | NEXT SHOW LISTS | HIDE LISTS

Class jsync.Lock

java.lang.Object
    |
    +----jsync.Lock

public class Lock
extends java.lang.Object
Class for supporting resource locking. Lock can be exclusive or shared, so multiple-readers single-writer protocol can be implemented. Locks can be nested, i.e. a thread can set a lock several times and resources will be unlocked only after execution of correspondent number of unlock requests.


Constructor Summary
 Lock()
 
 

Method Summary
boolean  setExclusive(long timeout)
Lock resource in exclusive mode.
void  setExclusive()
Lock resource in exclusive mode without limitation of waiting time.
boolean  setShared(long timeout)
Lock resource in shared mode.
void  setShared()
Lock resource in shared mode without limitation of waiting time.
void  unsetExclusive()
Release exclusive lock.
void  unsetShared()
Release shared lock.
 
Methods inherited from class java.lang.Object
 equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Lock

public Lock()
Method Detail

setShared

public boolean setShared(long timeout)
Lock resource in shared mode. Several threads can set shared lock, but no one can set exclusive lock until all shared locks will be released.
Parameters:
timeout - the maximum time to wait in milliseconds.
Returns:
true if lock is successfully set, false if resource can't be locked before expiration of timeout.

setShared

public void setShared()
Lock resource in shared mode without limitation of waiting time.

setExclusive

public boolean setExclusive(long timeout)
Lock resource in exclusive mode. Only one thread can lock resource in exclusive mode and all other shared and exclusive lock requests will be blocked until this lock is released.
Parameters:
timeout - the maximum time to wait in milliseconds.
Returns:
true if lock is successfully set, false if resource can't be locked within specified time.

setExclusive

public void setExclusive()
Lock resource in exclusive mode without limitation of waiting time.

unsetShared

public void unsetShared()
Release shared lock. Throws NotOwnerError if shared lock was not previously set by this thread.

unsetExclusive

public void unsetExclusive()
Release exclusive lock. If thread locked resource several time, than lock will be taken off only after correspondent number of unsetExclusive requests. Throws NotOwnerError if exclusive lock was not previously set by this thread.

Contents | Package | Class | Tree | Deprecated | Index | Help
PREV | NEXT SHOW LISTS | HIDE LISTS