Class PreciseMultiLock
- java.lang.Object
-
- com.complexible.common.util.concurrent.locks.PreciseMultiLock
-
-
Field Summary
Fields Modifier and Type Field Description static org.slf4j.Logger
LOGGER
-
Constructor Summary
Constructors Constructor Description PreciseMultiLock()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description long
heldBy(int lockID)
Returns the thread ID that holds the lock for the given ID or0
if it is not locked.void
lock(int lockID)
Locks the given ID, waiting indefinitely if another thread already has a lock.java.lang.String
toString()
boolean
tryLock(int lockID)
Tries to lock the given ID if it is possible to do so immediately and returntrue
.void
unlock(int lockID)
Unlocks the given ID.
-
-
-
Method Detail
-
lock
public void lock(int lockID)
Description copied from interface:MultiLock
Locks the given ID, waiting indefinitely if another thread already has a lock.
-
tryLock
public boolean tryLock(int lockID)
Description copied from interface:MultiLock
Tries 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 returnfalse
even 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 or0
if 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.IllegalArgumentException
Description copied from interface:MultiLock
Unlocks 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:
toString
in classjava.lang.Object
-
-