public class ConditionVariable extends Object
ConditionVariable:
Clock.elapsedRealtime() for timing block(long) timeout
intervals. ConditionVariable used System.currentTimeMillis()
prior to Android 10, which is not a correct clock to use for interval timing because it's
not guaranteed to be monotonic.
Clock.
isOpen().
open() and close() return whether they changed the variable's state.
| Constructor | Description |
|---|---|
ConditionVariable() |
Creates an instance using
Clock.DEFAULT. |
ConditionVariable(Clock clock) |
Creates an instance, which starts closed.
|
| Modifier and Type | Method | Description |
|---|---|---|
void |
block() |
Blocks until the condition is opened.
|
boolean |
block(long timeoutMs) |
Blocks until the condition is opened or until
timeoutMs have passed. |
void |
blockUninterruptible() |
Blocks until the condition is open.
|
boolean |
close() |
Closes the condition.
|
boolean |
isOpen() |
Returns whether the condition is opened.
|
boolean |
open() |
Opens the condition and releases all threads that are blocked.
|
public ConditionVariable()
Clock.DEFAULT.public ConditionVariable(Clock clock)
clock - The Clock whose Clock.elapsedRealtime() method is used to
determine when block(long) should time out.public boolean open()
public boolean close()
public void block()
throws InterruptedException
InterruptedException - If the thread is interrupted.public boolean block(long timeoutMs)
throws InterruptedException
timeoutMs have passed.timeoutMs - The maximum time to wait in milliseconds. If timeoutMs <= 0 then the
call will return immediately without blocking.InterruptedException - If the thread is interrupted.public void blockUninterruptible()
block(), this method will continue to block
if the calling thread is interrupted. If the calling thread was interrupted then its interrupted status will be set when the method returns.public boolean isOpen()