|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.atlassian.util.concurrent.BlockingReference<V>
V
- the value type@ThreadSafe public class BlockingReference<V>
A Reference with queue semantics where rather than getting the current
reference it is taken instead. Analogous to a single element
BlockingQueue
.
Note: this class does not support null elements being set(Object)
and will throw an exception. If the internal reference is null, then calls to
take()
or take(long, TimeUnit)
will block.
This class is most suited to SRSW usage. Multiple writers will overwrite each
other's elements, and if multiple readers are waiting to take a value, one
reader will be arbitrarily chosen (similar to Condition.signal()
).
BlockingQueue
Constructor Summary | |
---|---|
BlockingReference()
|
Method Summary | |
---|---|
boolean |
isEmpty()
Whether or not the current value is null or not. |
void |
set(V value)
Set the value of this reference. |
V |
take()
Takes the current element if it is not null and replaces it with null. |
V |
take(long timeout,
java.util.concurrent.TimeUnit unit)
Takes the current element if it is not null and replaces it with null. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public BlockingReference()
Method Detail |
---|
public V take() throws java.lang.InterruptedException
If the current thread:
InterruptedException
is thrown and the current thread's
interrupted status is cleared.
java.lang.InterruptedException
- if the current thread is interrupted while
waitingpublic V take(long timeout, java.util.concurrent.TimeUnit unit) throws java.util.concurrent.TimeoutException, java.lang.InterruptedException
TimeoutException
if the timeout is reached
before an element becomes available.
If the current thread:
InterruptedException
is thrown and the current thread's
interrupted status is cleared.
timeout
- the maximum time to waitunit
- the time unit of the timeout
argument
java.lang.InterruptedException
- if the current thread is interrupted while
waiting
java.util.concurrent.TimeoutException
- if the timeout is reached without another thread
having called set(Object)
.public void set(V value)
take()
or take(long, TimeUnit)
will be
released and given this value.
value
- the new value.public boolean isEmpty()
take()
or take(long, TimeUnit)
will not
block.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |