public final class AutoLock extends Object implements AutoCloseable, Lock
Lock
into an AutoCloseable
for use with try-with-resources:
Lock lock = ...;
...
AutoLock autoLock = new AutoLock(lock);
// Not locked
try (AutoLock al = autoLock.autoLock()) { // variable required but unused
// Locked
...
}
// Not locked
Constructor and Description |
---|
AutoLock()
Manages a new
ReentrantLock . |
AutoLock(Lock lock) |
Modifier and Type | Method and Description |
---|---|
AutoLock |
autoLock() |
void |
close()
Unlocks the underlying
Lock . |
void |
lock() |
void |
lockInterruptibly() |
Condition |
newCondition() |
String |
toString() |
boolean |
tryLock() |
boolean |
tryLock(long time,
TimeUnit unit) |
void |
unlock() |
public AutoLock()
ReentrantLock
.public AutoLock(Lock lock)
lock
- lock to managepublic void close()
Lock
.close
in interface AutoCloseable
public void lockInterruptibly() throws InterruptedException
lockInterruptibly
in interface Lock
InterruptedException
public boolean tryLock(long time, TimeUnit unit) throws InterruptedException
tryLock
in interface Lock
InterruptedException
public Condition newCondition()
newCondition
in interface Lock
Copyright © 2014–2018. All rights reserved.