public class SemaphoreLock extends java.lang.Object implements java.util.concurrent.locks.Lock
Lock
using a binary semaphore.
Unlike the ReentrantLock
this lock can be locked and unlocked by different threads.
Conditions are not supported.Constructor and Description |
---|
SemaphoreLock(boolean fair) |
Modifier and Type | Method and Description |
---|---|
void |
lock() |
void |
lockInterruptibly() |
java.util.concurrent.locks.Condition |
newCondition() |
boolean |
tryLock() |
boolean |
tryLock(long time,
java.util.concurrent.TimeUnit unit) |
void |
unlock() |
public SemaphoreLock(boolean fair)
public void lock()
lock
in interface java.util.concurrent.locks.Lock
Lock.lock()
public void lockInterruptibly() throws java.lang.InterruptedException
lockInterruptibly
in interface java.util.concurrent.locks.Lock
java.lang.InterruptedException
Lock.lockInterruptibly()
public java.util.concurrent.locks.Condition newCondition()
newCondition
in interface java.util.concurrent.locks.Lock
Lock.newCondition()
public boolean tryLock()
tryLock
in interface java.util.concurrent.locks.Lock
Lock.tryLock()
public boolean tryLock(long time, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException
tryLock
in interface java.util.concurrent.locks.Lock
java.lang.InterruptedException
Lock.tryLock(long, java.util.concurrent.TimeUnit)
public void unlock()
unlock
in interface java.util.concurrent.locks.Lock
Lock.unlock()