Class AutoLock
java.lang.Object
org.eclipse.jetty.util.thread.AutoLock
- All Implemented Interfaces:
 Serializable, AutoCloseable
- Direct Known Subclasses:
 AutoLock.WithCondition
Reentrant lock that can be used in a try-with-resources statement.
Typical usage:
try (AutoLock lock = this.lock.lock())
{
    // Something
}
- See Also:
 
- 
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classA reentrant lock with a condition that can be used in a try-with-resources statement. - 
Constructor Summary
Constructors - 
Method Summary
 
- 
Constructor Details
- 
AutoLock
public AutoLock() 
 - 
 - 
Method Details
- 
lock
 - 
lockInterruptibly
Acquires the lock interruptibly.
- Returns:
 - this AutoLock for unlocking
 - Throws:
 InterruptedException- See Also:
 
 - 
tryLock
Tries to acquire the lock.
Whether the lock was acquired can be tested with
isHeldByCurrentThread().Typical usage of this method is in
toString(), to avoid deadlocks when the implementation needs to lock to retrieve a consistent state to produce the string.- Returns:
 - this AutoLock for unlocking
 - See Also:
 
 - 
isHeldByCurrentThread
public boolean isHeldByCurrentThread()- Returns:
 - whether this lock is held by the current thread
 - See Also:
 
 - 
newCondition
 - 
close
public void close()- Specified by:
 closein interfaceAutoCloseable
 
 -