Class PreciseMultiLock
java.lang.Object
com.complexible.common.util.concurrent.locks.PreciseMultiLock
- All Implemented Interfaces:
MultiLock
Implementation of
MultiLock interface with precise locking which means no thread will block for an ID unless that ID
is locked by another thread.- Author:
- Evren Sirin
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionlongheldBy(int lockID) Returns the thread ID that holds the lock for the given ID or0if it is not locked.voidlock(int lockID) Locks the given ID, waiting indefinitely if another thread already has a lock.toString()booleantryLock(int lockID) Tries to lock the given ID if it is possible to do so immediately and returntrue.voidunlock(int lockID) Unlocks the given ID.
-
Field Details
-
LOGGER
public static final org.slf4j.Logger LOGGER
-
-
Constructor Details
-
PreciseMultiLock
public PreciseMultiLock()
-
-
Method Details
-
lock
public void lock(int lockID) Description copied from interface:MultiLockLocks the given ID, waiting indefinitely if another thread already has a lock. -
tryLock
public boolean tryLock(int lockID) Description copied from interface:MultiLockTries to lock the given ID if it is possible to do so immediately and returntrue. If the lock is already held by another thread, this function immediately returnsfalse. Since this class does not provide reentarant behavior, this function will returnfalseeven if it is the same thread that holds the lock before this function call. -
heldBy
public long heldBy(int lockID) Returns the thread ID that holds the lock for the given ID or0if it is not locked. This function is for monitoring purposes only and should not be used for synchronization. -
unlock
Description copied from interface:MultiLockUnlocks the given ID. There is no requirement that a thread that unlocks an ID must have locked that ID by callingMultiLock.lock(int).- Specified by:
unlockin interfaceMultiLock- Throws:
IllegalArgumentException
-
toString
-