public class EntryExitManager
extends java.lang.Object
Completion. Can block threads entering, abort waiting threads and wait for threads which have entered to exit.
When the gate is open, threads are not prevented from entering. When the gate is closed, threads will block on
enter(...), until the gate is opened (by some other thread).
Threads which enter the region must leave it by calling exit(). This will signal the exit of the thread. The
manager offers a method waitToClear(...) which will block
until all the currently entered threads have exited the region. Threads which enter during waitToClear(long, java.util.concurrent.TimeUnit) are not
detected.
closeGate()openGate()enter(...)exit()waitToClear(...)abortWaiters()AbortedException.| Constructor and Description |
|---|
EntryExitManager()
Create an
EntryExitManager, initially closed. |
| Modifier and Type | Method and Description |
|---|---|
void |
abortWaiters()
Abort all threads waiting to enter with an
AbortedException. |
boolean |
closeGate()
Close the gate, if allowed, so subsequent
enter()ing threads will block. |
boolean |
enter(long timeout,
java.util.concurrent.TimeUnit unit)
Returns
true immediately if the gate is open. |
boolean |
enter(TimeTracker tt)
Returns
true immediately if the gate is open. |
void |
exit()
This thread is exiting the region.
|
boolean |
isClosed()
Is the gate closed?
|
boolean |
openGate()
Opens the gate and wakes up all waiting threads.
|
boolean |
waitToClear(long timeout,
java.util.concurrent.TimeUnit unit)
Wait for current threads to exit region.
|
boolean |
waitToClear(TimeTracker tt)
Wait for current threads to exit region.
|
public EntryExitManager()
EntryExitManager, initially closed.public boolean isClosed()
true if the gate is closed, false otherwise.public boolean closeGate()
enter()ing threads will block.true in all cases.public boolean openGate()
true in all cases.public boolean enter(long timeout,
java.util.concurrent.TimeUnit unit)
throws java.lang.InterruptedException,
AbortedException
true immediately if the gate is open.
Otherwise if the gate is closed the thread blocks until one of the following occurs:
timeout - the time to wait for the gate to open.unit - the time unit of the timeout argument.false if timeout was reached before gate opens; true if gate is open or opens while we are waiting.java.lang.InterruptedException - if the callers thread is interrupted while waiting.AbortedException - if this thread is aborted by a stop() or close() while waiting.public boolean enter(TimeTracker tt) throws java.lang.InterruptedException, AbortedException
true immediately if the gate is open.
Otherwise if the gate is closed the thread blocks until one of the following occurs:
tt - the time tracker used to wait for the gate to open.false if timeout was reached before gate opens; true if gate is open or opens while we are waiting.java.lang.InterruptedException - if the callers thread is interrupted while waiting.AbortedException - if this thread is aborted by a stop() or close() while waiting.public void exit()
public boolean waitToClear(long timeout,
java.util.concurrent.TimeUnit unit)
throws java.lang.InterruptedException
timeout - max time to wait in units.unit - of time measurement for timeout.true if they all exited in time, false otherwise.java.lang.InterruptedException - if thread is interrupted and is waiting.public boolean waitToClear(TimeTracker tt) throws java.lang.InterruptedException
tt - timeout tracker.true if they all exited in time, false otherwise.java.lang.InterruptedException - if thread is interrupted and is waiting.public void abortWaiters()
AbortedException.Copyright © 2023. All rights reserved.