Package com.aspectran.core.util.thread
Class AutoLock
- java.lang.Object
-
- com.aspectran.core.util.thread.AutoLock
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.AutoCloseable
- Direct Known Subclasses:
AutoLock.WithCondition
public class AutoLock extends java.lang.Object implements java.lang.AutoCloseable, java.io.Serializable
Reentrant lock that can be used in a try-with-resources statement.Typical usage:
try (AutoLock lock = this.lock.lock()) { // Something }
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
AutoLock.WithCondition
A reentrant lock with a condition that can be used in a try-with-resources statement.
-
Constructor Summary
Constructors Constructor Description AutoLock()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
boolean
isHeldByCurrentThread()
AutoLock
lock()
Acquires the lock.java.util.concurrent.locks.Condition
newCondition()
-
-
-
Method Detail
-
lock
public AutoLock lock()
Acquires the lock.- Returns:
- this AutoLock for unlocking
-
isHeldByCurrentThread
public boolean isHeldByCurrentThread()
- Returns:
- whether this lock is held by the current thread
- See Also:
ReentrantLock.isHeldByCurrentThread()
-
newCondition
public java.util.concurrent.locks.Condition newCondition()
- Returns:
- a
Condition
associated with this lock
-
close
public void close()
- Specified by:
close
in interfacejava.lang.AutoCloseable
-
-