public class ThreadGate
extends java.lang.Object
Constructor and Description |
---|
ThreadGate(boolean open)
Creates a new gate in the state specified
|
ThreadGate(boolean open,
boolean fair)
Creates a new gate in the state specified.
|
Modifier and Type | Method and Description |
---|---|
void |
closeGate()
Closes the gate so no more threads can get through the gate
|
boolean |
isOpen()
Returns whether or not the gate is currently open
|
boolean |
isStateLocked()
Returns whether or not the state is currently locked
|
void |
lockGateClosed()
Locks the gate in the closed position.
|
void |
lockGateOpen()
Locks the gate in the open position.
|
void |
lockGateState()
Locks the current state of this gate.
|
void |
openGate()
Opens the gate to allow all threads through.
|
void |
passGate()
Blocks until the gate is open, the thread is interrupted, or returns immediately if the gate is open
|
void |
passGate(long waitDurationMilliseconds)
Blocks until the gate is open, the thread is interrupted, or returns immediately if the gate is open
|
boolean |
tryPassGate()
Attempts to pass through the gate.
|
void |
unlockGateState()
Unlocks the current state of this gate.
|
public ThreadGate(boolean open)
open
- The state of the gate.public ThreadGate(boolean open, boolean fair)
open
- The state of the gate.fair
- True if all threads waiting at the gate should be allowed through when it is opened, even if it is closed again before they all get started
again. False to enforce a strict policy that threads only proceed when the gate is open, regardless of when they got there.public void passGate() throws java.lang.InterruptedException
java.lang.InterruptedException
- If the thread was interrupted.public void passGate(long waitDurationMilliseconds) throws java.util.concurrent.TimeoutException, java.lang.InterruptedException
waitDurationMilliseconds
- The maximum amount of time to wait before timing out, a negative or zero value indicates to wait indefinitelyjava.lang.InterruptedException
- If the thread was interrupted.java.util.concurrent.TimeoutException
- If the gate was not open during the given duration (or was opened but closed again before this thread was awakened and run, and the
gate is operating in an unfair mode)public boolean tryPassGate()
public void openGate()
public void closeGate()
public void lockGateState()
public void unlockGateState()
public void lockGateOpen()
public void lockGateClosed()
public boolean isOpen()
public boolean isStateLocked()