public class Barrier extends Object
| Modifier and Type | Field and Description |
|---|---|
static long |
DEFAULT_TIMEOUT
The default timeout that will be used by
await(). |
static String |
DEFAULT_TIMEOUT_PROPERTY
A system property that may be used to override the value of
DEFAULT_TIMEOUT: "com.atlassian.utt.concurrency.Barrier.DEFAULT_TIMEOUT". |
| Constructor and Description |
|---|
Barrier() |
| Modifier and Type | Method and Description |
|---|---|
void |
await()
Waits
DEFAULT_TIMEOUT for the barrier to be signalled. |
void |
await(long timeout)
Waits the specified time in milliseconds for the barrier to be signalled.
|
static long |
getDefaultTimeout()
Returns the
DEFAULT_TIMEOUT, or whatever value DEFAULT_TIMEOUT_PROPERTY specified
to override it with. |
void |
signal()
Signals (drops) this barrier.
|
boolean |
trySignal()
Attempts to signal this barrier.
|
public static final String DEFAULT_TIMEOUT_PROPERTY
DEFAULT_TIMEOUT: "com.atlassian.utt.concurrency.Barrier.DEFAULT_TIMEOUT".public static final long DEFAULT_TIMEOUT
await().
This is meant to make the test time out rather than deadlock indefinitely when the test does not follow the expected logical pathway. If you are trying to debug something, then you may need to set it to a much larger value to prevent barriers from timing out while you step through the tests.
DEFAULT_TIMEOUT_PROPERTY,
Constant Field Valuespublic static long getDefaultTimeout()
DEFAULT_TIMEOUT, or whatever value DEFAULT_TIMEOUT_PROPERTY specified
to override it with.public void signal()
Once the barrier has been signalled, it can't be signalled again or re-raised — it is done.
Since this is meant for coordinating various threads within a test, getting signalled more than
once probably means that someone has made a mistake. If it really does make sense for the barrier
to get signalled multiple times, you probably want a normal CyclicBarrier, or maybe just
to use trySignal() if it is only necessary to block the first time that something is called.
AssertionError - if the barrier has already been signalled by somebody elsepublic boolean trySignal()
As documented for signal(), a Barrier may only be signalled once. If for some
reason you want to be able to drop it from somewhere that gets called multiple times and don't
mind that more than one attempt is made to drop the barrier, then you can use trySignal()
instead.
true if the barrier is successfully signalled; false if unable to signal
the barrier because this has already happened.public void await()
DEFAULT_TIMEOUT for the barrier to be signalled.AssertionError - if this thread is interrupted while awaiting the signal or if the timeout expires
without the barrier being signalled.public void await(long timeout)
AssertionError - if this thread is interrupted while awaiting the signal or if the timeout expires
without the barrier being signalled.Copyright © 2017 Atlassian. All rights reserved.