public interface ReentrantLock
限定符和类型 | 方法和说明 |
---|---|
void |
lock()
获取锁
|
static ReentrantLock |
newLock(java.lang.String resource)
新建锁
|
boolean |
tryLock()
尝试获取锁对象
1、如果获取不到立即返回false,
2、如果获取到返回true
|
boolean |
tryLock(long waitTime,
java.util.concurrent.TimeUnit unit)
tryLock(long time, TimeUnit unit)方法和tryLock()方法是类似的,只不过区别在于这个方法在拿不到锁时会等待一定的时间
在时间期限之内如果还拿不到锁,就返回false
|
void |
unlock()
释放锁
|
static ReentrantLock newLock(java.lang.String resource)
void lock()
void unlock()
boolean tryLock()
boolean tryLock(long waitTime, java.util.concurrent.TimeUnit unit)
waitTime
- 等待时间unit
- 时间单位 小时、分、秒、毫秒等