public class SoftLatch extends Object
Park/unpark example: use open() to unpark and waitAndClose() to park.
AutoResetEvent example: use open() to set, close() to reset, and waitAndClose() to wait.
ManualResetEvent example: use open() to set, close() to reset, and wait() to wait.
Note: never synchronize on instances of this class.
Modifier and Type | Field and Description |
---|---|
private boolean |
open |
Constructor and Description |
---|
SoftLatch(boolean open)
Creates a new latch, with the given open/closed state.
|
Modifier and Type | Method and Description |
---|---|
void |
await()
Wait for the latch to become open.
|
void |
close()
Close the latch, causing future calls to wait() or waitAndClose()
to block.
|
void |
open()
Open the latch and let all of the thread(s) waiting on it through.
|
void |
waitAndClose()
Wait for the latch to become open, and then close it and return.
|
private boolean open
public SoftLatch(boolean open)
open
- whether the latch is open at the beginningpublic void open()
public void close()
public void await()
public void waitAndClose()