public final class Blocker extends Object
This class should be used when the condition has to be evaluated and a
notification is not possible; if it is possible to get a notification when
the condition may change Object.wait()
and Object.notify()
/
Object.notifyAll()
should be used instead (See Waiter
which
should be the preferred method if possible).
If the thread does not need to be blocked, but a condition change
notification is still not possible, use AsyncWaiter
instead.
Modifier and Type | Method and Description |
---|---|
static void |
wait(Condition condition,
int retries,
javax.measure.Measurable<javax.measure.quantity.Duration> period)
Blocks the current thread if the condition isn't
true until it
becomes true or the maximum number of retries has been reached. |
static void |
wait(Condition condition,
javax.measure.Measurable<javax.measure.quantity.Duration> period)
Blocks the current thread if the condition isn't
true until it
becomes true . |
public static void wait(Condition condition, int retries, javax.measure.Measurable<javax.measure.quantity.Duration> period) throws NullPointerException, IllegalArgumentException, InterruptedException
true
until it
becomes true
or the maximum number of retries has been reached.
The Blocker may unblock even if the condition has not been met if the maximum number of retries is reached, thus it is recommended to evaluate the condition after the Blocker unblocks.
condition
- condition to evaluateretries
- maximum number of retriesperiod
- duration of one cycle in a repeating event; condition
evaluation period or delay between retries (time the thread will
be in sleep mode until a new evaluation is performed)NullPointerException
- if eithercondition
or
delay
is null
InterruptedException
- if any thread has interrupted the current
threadIllegalArgumentException
- if retries
is less or equals
to zeropublic static void wait(Condition condition, javax.measure.Measurable<javax.measure.quantity.Duration> period) throws NullPointerException, InterruptedException
true
until it
becomes true
.condition
- condition to evaluateperiod
- duration of one cycle in a repeating event; condition
evaluation periodNullPointerException
- if eithercondition
or
delay
is null
InterruptedException
- if any thread has interrupted the current
threadCopyright © 2016. All Rights Reserved.