Class PreciseMultiLock
- java.lang.Object
-
- com.complexible.common.util.concurrent.locks.PreciseMultiLock
-
-
Field Summary
Fields Modifier and Type Field Description static org.slf4j.LoggerLOGGER
-
Constructor Summary
Constructors Constructor Description PreciseMultiLock()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description longheldBy(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.java.lang.StringtoString()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.
-
-
-
Method Detail
-
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
public void unlock(int lockID) throws java.lang.IllegalArgumentExceptionDescription 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).
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-