Package com.aspectran.core.util.thread
Class AutoLock.WithCondition
- java.lang.Object
-
- com.aspectran.core.util.thread.AutoLock
-
- com.aspectran.core.util.thread.AutoLock.WithCondition
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.AutoCloseable
- Enclosing class:
- AutoLock
public static class AutoLock.WithCondition extends AutoLock
A reentrant lock with a condition that can be used in a try-with-resources statement.Typical usage:
// Waiting try (AutoLock lock = _lock.lock()) { lock.await(); } // Signaling try (AutoLock lock = _lock.lock()) { lock.signalAll(); }
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.aspectran.core.util.thread.AutoLock
AutoLock.WithCondition
-
-
Constructor Summary
Constructors Constructor Description WithCondition()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
await()
boolean
await(long time, java.util.concurrent.TimeUnit unit)
AutoLock.WithCondition
lock()
Acquires the lock.void
signal()
void
signalAll()
-
Methods inherited from class com.aspectran.core.util.thread.AutoLock
close, isHeldByCurrentThread, newCondition
-
-
-
-
Method Detail
-
lock
public AutoLock.WithCondition lock()
Description copied from class:AutoLock
Acquires the lock.
-
signal
public void signal()
- See Also:
Condition.signal()
-
signalAll
public void signalAll()
- See Also:
Condition.signalAll()
-
await
public void await() throws java.lang.InterruptedException
- Throws:
java.lang.InterruptedException
- if the current thread is interrupted- See Also:
Condition.await()
-
await
public boolean await(long time, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException
- Parameters:
time
- the time to waitunit
- the time unit- Returns:
- false if the waiting time elapsed
- Throws:
java.lang.InterruptedException
- if the current thread is interrupted- See Also:
Condition.await(long, TimeUnit)
-
-