Package org.jgroups.blocks.locking
Class LockService.LockImpl
- java.lang.Object
-
- org.jgroups.blocks.locking.LockService.LockImpl
-
- All Implemented Interfaces:
java.util.concurrent.locks.Lock
- Enclosing class:
- LockService
protected class LockService.LockImpl extends java.lang.Object implements java.util.concurrent.locks.Lock
Implementation ofLock
. This is a client stub communicates with a server equivalent. The semantics are more or less those ofLock
, but may differ slightly. There is no reference counting of lock owners, so acquisition of a lock already held by a thread is a no-op. Also, releasing the lock after it was already released is a no-op as well. An exact description is provided below.
-
-
Constructor Summary
Constructors Constructor Description LockImpl(java.lang.String name)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
lock()
Blocks until the lock has been acquired.void
lockInterruptibly()
If the thread is interrupted at entry, the call will throw an InterruptedException immediately and the lock won't be acquired.java.util.concurrent.locks.Condition
newCondition()
This condition object is only allowed to work 1 for each lock.java.lang.String
toString()
boolean
tryLock()
If the thread is interrupted at entry or during the call, no InterruptedException will be thrown, but the thread's status will be set to interrupted upon return.boolean
tryLock(long time, java.util.concurrent.TimeUnit unit)
* If the thread is interrupted at entry, the call will throw an InterruptedException immediately and the lock won't be acquired.void
unlock()
Releases a lock.
-
-
-
Method Detail
-
lock
public void lock()
Blocks until the lock has been acquired. Masks interrupts; if an interrupt was received on entry or while waiting for the lock acquisition, it won't cause the call to return. However, the thread's status will be set to interrupted when the call returns.- Specified by:
lock
in interfacejava.util.concurrent.locks.Lock
-
lockInterruptibly
public void lockInterruptibly() throws java.lang.InterruptedException
If the thread is interrupted at entry, the call will throw an InterruptedException immediately and the lock won't be acquired. If the thread is interrupted while waiting for the lock acquition, an InterruptedException will also be thrown immediately. The thread's interrupt status will not be set after the call returns.- Specified by:
lockInterruptibly
in interfacejava.util.concurrent.locks.Lock
- Throws:
java.lang.InterruptedException
-
tryLock
public boolean tryLock()
If the thread is interrupted at entry or during the call, no InterruptedException will be thrown, but the thread's status will be set to interrupted upon return. An interrupt has therefore no impact on the return value (success or failure).- Specified by:
tryLock
in interfacejava.util.concurrent.locks.Lock
-
tryLock
public boolean tryLock(long time, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException
* If the thread is interrupted at entry, the call will throw an InterruptedException immediately and the lock won't be acquired. If the thread is interrupted while waiting for the lock acquition, an InterruptedException will also be thrown immediately. The thread's interrupt status will not be set after the call returns.- Specified by:
tryLock
in interfacejava.util.concurrent.locks.Lock
- Parameters:
time
-unit
-- Returns:
- Throws:
java.lang.InterruptedException
-
unlock
public void unlock()
Releases a lock. Contrary to the parent's implementation, this method can be called more than once: the release of a lock that has already been released, or is not owned by this thread is a no-op.- Specified by:
unlock
in interfacejava.util.concurrent.locks.Lock
-
newCondition
public java.util.concurrent.locks.Condition newCondition()
This condition object is only allowed to work 1 for each lock. If more than 1 condition is created for this lock, they both will be awaiting/signalling on the same lock- Specified by:
newCondition
in interfacejava.util.concurrent.locks.Lock
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-